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)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Oct 2024 14:58:20 +0000 (16:58 +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 '.'.

(cherry picked from commit 944a224358ab2865a3a1c0bf700aba38550b19cc)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/debug.c

index 432d3fd..c4dc31b 100644 (file)
@@ -1787,6 +1787,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)
@@ -1794,6 +1796,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);
                }
@@ -1807,6 +1815,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);
                }