ipl_tools: Copy strings correctly

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 <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-11-07 08:56:35 +01:00
parent cf39f26dee
commit 9f8d245f92
3 changed files with 9 additions and 4 deletions

View File

@@ -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:

View File

@@ -13,6 +13,7 @@
#include <ctype.h>
#include <sys/sysmacros.h>
#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;

View File

@@ -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;