mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
ipl_tools: Change buffer size and copy strings correctly
Change the buffer size to what we actually need and use util_strlcpy() to correctly copy strings. This gets rid of the following GCC8 compile warnings: fcp.c: In function ‘fcp_wwpn_get’: fcp.c:44:2: warning: ‘strncpy’ output may be truncated copying 20 bytes from a string of length 4095 [-Wstringop-truncation] strncpy(wwpn, buf, 20); ^~~~~~~~~~~~~~~~~~~~~~ fcp.c: In function ‘fcp_lun_get’: fcp.c:65:2: warning: ‘strncpy’ output may be truncated copying 20 bytes from a string of length 4095 [-Wstringop-truncation] strncpy(lun, buf, 20); ^~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include "lib/util_libc.h"
|
||||
#include "ipl_tools.h"
|
||||
|
||||
/*
|
||||
@@ -30,7 +31,7 @@ int fcp_is_device(const char *devno)
|
||||
*/
|
||||
void fcp_wwpn_get(const char *device, char *wwpn)
|
||||
{
|
||||
char path[PATH_MAX], buf[4096];
|
||||
char path[PATH_MAX], buf[20];
|
||||
FILE *fh;
|
||||
int rc;
|
||||
|
||||
@@ -41,7 +42,7 @@ void fcp_wwpn_get(const char *device, char *wwpn)
|
||||
rc = fscanf(fh, "%s", buf);
|
||||
if (rc <= 0)
|
||||
ERR_EXIT("Could not lookup WWPN \"%s\"", path);
|
||||
strncpy(wwpn, buf, 20);
|
||||
util_strlcpy(wwpn, buf, 20);
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ void fcp_wwpn_get(const char *device, char *wwpn)
|
||||
*/
|
||||
void fcp_lun_get(const char *device, char *lun)
|
||||
{
|
||||
char path[PATH_MAX], buf[4096];
|
||||
char path[PATH_MAX], buf[20];
|
||||
FILE *fh;
|
||||
int rc;
|
||||
|
||||
@@ -62,7 +63,7 @@ void fcp_lun_get(const char *device, char *lun)
|
||||
rc = fscanf(fh, "%s", buf);
|
||||
if (rc <= 0)
|
||||
ERR_EXIT("Could not lookup LUN \"%s\"", path);
|
||||
strncpy(lun, buf, 20);
|
||||
util_strlcpy(lun, buf, 20);
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user