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]>
  • Loading branch information
wlallemand authored and wtarreau committed Oct 24, 2024
1 parent f215ad3 commit cdb7dac
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 @@ -1787,13 +1787,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 @@ -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);
}
Expand Down

0 comments on commit cdb7dac

Please sign in to comment.