]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: systemd-wrapper: fix locating of haproxy binary
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Apr 2014 13:34:34 +0000 (15:34 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Apr 2014 13:52:49 +0000 (15:52 +0200)
OpenBSD complains this way due to strncat() :

src/haproxy-systemd-wrapper.o(.text+0xd5): In function `spawn_haproxy':
src/haproxy-systemd-wrapper.c:33: warning: strcat() is almost always misused, please use strlcat()

In fact, the code before strncat() here is wrong, because it may
dereference a NULL if /proc/self/exe is not readable. So fix it
and get rid of strncat() at the same time.

No backport is needed.

src/haproxy-systemd-wrapper.c

index c63f41ff7df6f538721b3b0f1cb50fc8f39e642e..8485dcd11da889cd91c3a94fa124c3d170882fb1 100644 (file)
@@ -24,13 +24,18 @@ static char **main_argv;
 
 static void locate_haproxy(char *buffer, size_t buffer_size)
 {
-       char* end = NULL;
+       char *end = NULL;
+
        if (readlink("/proc/self/exe", buffer, buffer_size) > 0)
                end = strrchr(buffer, '/');
-       if (end == NULL)
+
+       if (end == NULL) {
                strncpy(buffer, "/usr/sbin/haproxy", buffer_size);
+               return;
+       }
        end[1] = '\0';
-       strncat(buffer, "haproxy", buffer_size);
+       strncpy(end + 1, "haproxy", buffer + buffer_size - (end + 1));
+       buffer[buffer_size - 1] = '\0';
 }
 
 static void spawn_haproxy(char **pid_strv, int nb_pid)