From 9f8d245f92fb2b918daea399b9e7877d21244166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 7 Nov 2018 08:56:35 +0100 Subject: [PATCH] ipl_tools: Copy strings correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use util_strlcpy() to copy strings correctly and get rid of the following GCC8 compile warnings: main.c: In function ‘main’: main.c:34:2: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation] strncpy(g.prog_name, argv[0], sizeof(g.prog_name)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘set_bootprog’, inlined from ‘parse_chreipl_options’ at cmd_chreipl.c:510:4: cmd_chreipl.c:185:2: warning: ‘strncpy’ specified bound 11 equals destination size [-Wstringop-truncation] strncpy(l.bootprog, bootprog, sizeof(l.bootprog)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmd_chreipl.c: In function ‘set_reipl_type’: cmd_chreipl.c:297:2: warning: ‘strncpy’ specified bound 15 equals destination size [-Wstringop-tr uncation] strncpy(l.dev, dev_name, sizeof(l.dev)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- ipl_tools/Makefile | 4 +++- ipl_tools/cmd_chreipl.c | 5 +++-- ipl_tools/main.c | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ipl_tools/Makefile b/ipl_tools/Makefile index 506d5cdc..c5e99787 100644 --- a/ipl_tools/Makefile +++ b/ipl_tools/Makefile @@ -1,11 +1,13 @@ include ../common.mak +libs = $(rootdir)/libutil/libutil.a + all: chreipl lsreipl chshut lsshut objects = main.o ccw.o fcp.o system.o shutdown.o \ cmd_lsshut.o cmd_chshut.o cmd_lsreipl.o cmd_chreipl.o proc.o -chreipl: $(objects) +chreipl: $(objects) $(libs) $(LINK) $(ALL_LDFLAGS) $^ $(LDLIBS) -o $@ lsreipl: diff --git a/ipl_tools/cmd_chreipl.c b/ipl_tools/cmd_chreipl.c index 5ba0b224..5e59199b 100644 --- a/ipl_tools/cmd_chreipl.c +++ b/ipl_tools/cmd_chreipl.c @@ -13,6 +13,7 @@ #include #include +#include "lib/util_libc.h" #include "lib/zt_common.h" #include "ipl_tools.h" @@ -182,7 +183,7 @@ static void set_bootprog(const char *bootprog) ERR_EXIT("Bootprog \"%s\" is not a decimal number", bootprog); if (bootprog_int > UINT_MAX) ERR_EXIT("Invalid bootprog specified"); - strncpy(l.bootprog, bootprog, sizeof(l.bootprog)); + util_strlcpy(l.bootprog, bootprog, sizeof(l.bootprog)); l.bootprog_set = 1; } @@ -294,7 +295,7 @@ static int set_reipl_type(const char *dev_name) else return -1; - strncpy(l.dev, dev_name, sizeof(l.dev)); + util_strlcpy(l.dev, dev_name, sizeof(l.dev)); dev_from_part(l.dev); l.dev_set = 1; return 0; diff --git a/ipl_tools/main.c b/ipl_tools/main.c index 6a6cc97a..f78f544e 100644 --- a/ipl_tools/main.c +++ b/ipl_tools/main.c @@ -9,7 +9,9 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#include "lib/util_libc.h" #include "lib/zt_common.h" + #include "ipl_tools.h" struct globals g; @@ -31,7 +33,7 @@ void __noreturn print_version_exit(void) int main(int argc, char *argv[]) { - strncpy(g.prog_name, argv[0], sizeof(g.prog_name)); + util_strlcpy(g.prog_name, argv[0], sizeof(g.prog_name)); if (strstr(argv[0], "chreipl") != NULL) { cmd_chreipl(argc, argv); return 0;