Skip to content

Commit

Permalink
MINOR: cli: remove non-printable characters from 'debug dev fd'
Browse files Browse the repository at this point in the history
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 944a224)
Signed-off-by: Willy Tarreau <[email protected]>
(cherry picked from commit cdb7dac)
Signed-off-by: Willy Tarreau <[email protected]>
  • Loading branch information
wlallemand authored and wtarreau committed Oct 24, 2024
1 parent e3a60a7 commit 7d21522
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1690,13 +1690,21 @@ 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)
port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port);
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);
}
Expand All @@ -1710,6 +1718,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);
}
Expand Down

0 comments on commit 7d21522

Please sign in to comment.