]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: remove non-printable characters from 'debug dev fd'
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 24 Oct 2024 14:31:56 +0000 (16:31 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 24 Oct 2024 14:45:11 +0000 (16:45 +0200)
When using 'debug dev fd', the output of laddr and raddr can contain
some garbage.

This patch replaces any control or non-printable character by a '.'.

src/debug.c

index c0585914944a25dbecca91ef7bc79d3d24dfaf11..eef4da8cf6a78d663eb548fd0205de1a3b88943e 100644 (file)
@@ -1865,6 +1865,8 @@ static int debug_iohandler_fd(struct appctx *appctx)
 
                salen = sizeof(sa);
                if (getsockname(fd, (struct sockaddr *)&sa, &salen) != -1) {
+                       int i;
+
                        if (sa.ss_family == AF_INET)
                                port = ntohs(((const struct sockaddr_in *)&sa)->sin_port);
                        else if (sa.ss_family == AF_INET6)
@@ -1872,6 +1874,12 @@ static int debug_iohandler_fd(struct appctx *appctx)
                        else
                                port = 0;
                        addrstr = sa2str(&sa, port, 0);
+                       /* cleanup the output */
+                       for  (i = 0; i < strlen(addrstr); i++) {
+                               if (iscntrl((unsigned char)addrstr[i]) || !isprint((unsigned char)addrstr[i]))
+                                       addrstr[i] = '.';
+                       }
+
                        chunk_appendf(&trash, " laddr=%s", addrstr);
                        free(addrstr);
                }
@@ -1885,6 +1893,11 @@ static int debug_iohandler_fd(struct appctx *appctx)
                        else
                                port = 0;
                        addrstr = sa2str(&sa, port, 0);
+                       /* cleanup the output */
+                       for  (i = 0; i < strlen(addrstr); i++) {
+                               if ((iscntrl((unsigned char)addrstr[i])) || !isprint((unsigned char)addrstr[i]))
+                                       addrstr[i] = '.';
+                       }
                        chunk_appendf(&trash, " raddr=%s", addrstr);
                        free(addrstr);
                }