From d85cf20981cb48665ba6ded743c10ab930c4350e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Mon, 22 Oct 2018 17:00:22 +0200 Subject: [PATCH] dump2tar: Change SET_STR_FIELD to copy strings correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure strings are properly copied in the SET_STR_FIELD macro by using util_strlcpy(). This gets rid of the following GCC8 compile warnings: In function ‘init_header’, inlined from ‘emit_header’ at tar.c:189:2: tar.c:81:2: warning: ‘strncpy’ specified bound 100 equals destination size [-Wstringop-truncation] strncpy((obj)->name, (value), sizeof((obj)->name)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tar.c:94:2: note: in expansion of macro ‘SET_STR_FIELD’ SET_STR_FIELD(header, name, filename); ^~~~~~~~~~~~~ tar.c:81:2: warning: ‘strncpy’ specified bound 100 equals destination size [-Wstringop-truncation] strncpy((obj)->name, (value), sizeof((obj)->name)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tar.c:94:2: note: in expansion of macro ‘SET_STR_FIELD’ SET_STR_FIELD(header, name, filename); ^~~~~~~~~~~~~ tar.c:81:2: warning: ‘strncpy’ specified bound 100 equals destination size [-Wstringop-truncation] strncpy((obj)->name, (value), sizeof((obj)->name)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tar.c:96:3: note: in expansion of macro ‘SET_STR_FIELD’ SET_STR_FIELD(header, linkname, link); ^~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- dump2tar/src/tar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dump2tar/src/tar.c b/dump2tar/src/tar.c index 8ad44f91..bc5649a0 100644 --- a/dump2tar/src/tar.c +++ b/dump2tar/src/tar.c @@ -78,7 +78,7 @@ static void set_time(char *dest, size_t len, time_t value) #define SET_TIME_FIELD(obj, name, value) \ set_time((obj)->name, sizeof((obj)->name), (time_t) (value)) #define SET_STR_FIELD(obj, name, value) \ - strncpy((obj)->name, (value), sizeof((obj)->name)) + util_strlcpy((obj)->name, (value), sizeof((obj)->name)) /* Initialize the tar file @header with the provided data */ static void init_header(struct tar_header *header, const char *filename,