From d668dcfa97d7140b9b5f10afd345b35e641ac14d Mon Sep 17 00:00:00 2001 From: Willy Tarreau <w@1wt.eu> Date: Wed, 11 Dec 2019 16:29:10 +0100 Subject: [PATCH] BUILD/MINOR: unix sockets: silence an absurd gcc warning about strncpy() Apparently gcc developers decided that strncpy() semantics are no longer valid and now deserve a warning, especially if used exactly as designed. This results in issue #304. Let's just remove one to the target size to please her majesty gcc, the God of C Compilers, who tries hard to make users completely eliminate any use of string.h and reimplement it by themselves at much higher risks. Pfff.... This can be backported to stable version, the fix is harmless since it ignores the last zero that is already set on next line. (cherry picked from commit 719e07c989be48a69fcfcaa404d12d7478de8a1b) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit b5085dfe892bef654841103173079434a32c2a24) Signed-off-by: Willy Tarreau <w@1wt.eu> --- src/haproxy.c | 2 +- src/proto_uxst.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index d29504126..ba3c8aedc 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1010,7 +1010,7 @@ static int get_old_sockets(const char *unixsocket) unixsocket); goto out; } - strncpy(addr.sun_path, unixsocket, sizeof(addr.sun_path)); + strncpy(addr.sun_path, unixsocket, sizeof(addr.sun_path) - 1); addr.sun_path[sizeof(addr.sun_path) - 1] = 0; addr.sun_family = PF_UNIX; ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 7263240f1..1068fe491 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -250,7 +250,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle goto err_return; } - strncpy(addr.sun_path, tempname, sizeof(addr.sun_path)); + strncpy(addr.sun_path, tempname, sizeof(addr.sun_path) - 1); addr.sun_path[sizeof(addr.sun_path) - 1] = 0; } else {