From 944a224358ab2865a3a1c0bf700aba38550b19cc Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 24 Oct 2024 16:31:56 +0200 Subject: [PATCH] MINOR: cli: remove non-printable characters from 'debug dev fd' 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/debug.c b/src/debug.c index c058591494..eef4da8cf6 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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); }