]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD/MINOR: unix sockets: silence an absurd gcc warning about strncpy()
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Dec 2019 15:29:10 +0000 (16:29 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Dec 2019 15:29:10 +0000 (16:29 +0100)
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.

src/haproxy.c
src/proto_uxst.c

index a7f6a247dd3633fe525989a25e4519dd34642ce7..30c43c11ba8532baef9f453e5f175b237e5e1e1c 100644 (file)
@@ -1140,7 +1140,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));
index c5acfcec7603361d5f4775f2db31a81fe9f2b14f..4c32f7eb07038f1baa23cf182704e1b7f200b643 100644 (file)
@@ -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 {