]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cli: make sure the "getsock" command is only called on connections
authorWilly Tarreau <w@1wt.eu>
Thu, 20 Sep 2018 09:22:29 +0000 (11:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 20 Sep 2018 09:42:15 +0000 (11:42 +0200)
Theorically nothing would prevent a front applet form connecting to a stats
socket, and if a "getsock" command was issued, it would cause a crash. Right
now nothing in the code does this so in its current form there is no impact.

It may or may not be backported to 1.8.

src/cli.c

index 6d054830340ffb97cddc2d8375547a59f1e25999..ed17aac77c9ac50c6d59aba81ae18e2c1e027616 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1376,11 +1376,18 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
        int tot_fd_nb = 0;
        struct proxy *px;
        int i = 0;
-       int fd = remote->handle.fd;
+       int fd = -1;
        int curoff = 0;
-       int old_fcntl;
+       int old_fcntl = -1;
        int ret;
 
+       if (!remote) {
+               ha_warning("Only works on real connections\n");
+               goto out;
+       }
+
+       fd = remote->handle.fd;
+
        /* Temporary set the FD in blocking mode, that will make our life easier */
        old_fcntl = fcntl(fd, F_GETFL);
        if (old_fcntl < 0) {
@@ -1529,7 +1536,7 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
        }
 
 out:
-       if (old_fcntl >= 0 && fcntl(fd, F_SETFL, old_fcntl) == -1) {
+       if (fd >= 0 && old_fcntl >= 0 && fcntl(fd, F_SETFL, old_fcntl) == -1) {
                ha_warning("Cannot make the unix socket non-blocking\n");
                goto out;
        }