From 7df8edd88a29de3ac87f794cfa135a4e14119c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 7 Nov 2018 10:12:46 +0100 Subject: [PATCH] ipl_tools: Change buffer size and copy strings correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- ipl_tools/fcp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ipl_tools/fcp.c b/ipl_tools/fcp.c index 6284851f..6532a6da 100644 --- a/ipl_tools/fcp.c +++ b/ipl_tools/fcp.c @@ -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); }