Skip to content

Commit 944a224

Browse files
committed
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 '.'.
1 parent 4adb2d8 commit 944a224

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/debug.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,13 +1865,21 @@ static int debug_iohandler_fd(struct appctx *appctx)
18651865

18661866
salen = sizeof(sa);
18671867
if (getsockname(fd, (struct sockaddr *)&sa, &salen) != -1) {
1868+
int i;
1869+
18681870
if (sa.ss_family == AF_INET)
18691871
port = ntohs(((const struct sockaddr_in *)&sa)->sin_port);
18701872
else if (sa.ss_family == AF_INET6)
18711873
port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port);
18721874
else
18731875
port = 0;
18741876
addrstr = sa2str(&sa, port, 0);
1877+
/* cleanup the output */
1878+
for (i = 0; i < strlen(addrstr); i++) {
1879+
if (iscntrl((unsigned char)addrstr[i]) || !isprint((unsigned char)addrstr[i]))
1880+
addrstr[i] = '.';
1881+
}
1882+
18751883
chunk_appendf(&trash, " laddr=%s", addrstr);
18761884
free(addrstr);
18771885
}
@@ -1885,6 +1893,11 @@ static int debug_iohandler_fd(struct appctx *appctx)
18851893
else
18861894
port = 0;
18871895
addrstr = sa2str(&sa, port, 0);
1896+
/* cleanup the output */
1897+
for (i = 0; i < strlen(addrstr); i++) {
1898+
if ((iscntrl((unsigned char)addrstr[i])) || !isprint((unsigned char)addrstr[i]))
1899+
addrstr[i] = '.';
1900+
}
18881901
chunk_appendf(&trash, " raddr=%s", addrstr);
18891902
free(addrstr);
18901903
}

0 commit comments

Comments
 (0)