From 2962248e7be2c7812d58b368c34f0de6c0d00164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Thu, 8 Nov 2018 15:56:46 +0100 Subject: [PATCH] qethqoat: Use util_strlcpy() to copy strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the more robust util_strlcpy() to copy strings instead of strncpy(). This fixes the following GCC8 compile warnings: qethqoat.c: In function ‘main’: qethqoat.c:616:2: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] strncpy(ifr.ifr_name, opts.ifname, IFNAMSIZ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- qethqoat/Makefile | 4 +++- qethqoat/qethqoat.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/qethqoat/Makefile b/qethqoat/Makefile index 5ac87fb1..80fe56f8 100644 --- a/qethqoat/Makefile +++ b/qethqoat/Makefile @@ -2,7 +2,9 @@ include ../common.mak all: qethqoat -qethqoat: qethqoat.o +libs = $(rootdir)/libutil/libutil.a + +qethqoat: qethqoat.o $(libs) install: all $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man8 diff --git a/qethqoat/qethqoat.c b/qethqoat/qethqoat.c index 7110c283..96dd4d36 100644 --- a/qethqoat/qethqoat.c +++ b/qethqoat/qethqoat.c @@ -24,6 +24,7 @@ #include #include +#include "lib/util_libc.h" #include "lib/zt_common.h" #include "qethqoat.h" @@ -541,6 +542,7 @@ int main(int argc, char **argv) opts.raw = 0; opts.scope = 1; opts.file = NULL; + opts.ifname = NULL; while ((c = getopt_long(argc, argv, qethqoat_opts_str, qethqoat_opts, &index)) != -1) { @@ -613,7 +615,7 @@ int main(int argc, char **argv) return 1; } - strncpy(ifr.ifr_name, opts.ifname, IFNAMSIZ); + util_strlcpy(ifr.ifr_name, opts.ifname, IFNAMSIZ); oat_data.command = opts.scope; ifr.ifr_ifru.ifru_data = (void *)&oat_data;