Skip to content

Commit

Permalink
pike: use snprintf() instead of sprintf()
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Nov 25, 2019
1 parent dadbc0c commit 7be06d4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/modules/pike/pike_top.c
Expand Up @@ -41,22 +41,28 @@ char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff,
int buffsize )
{
unsigned short *ipv6_ptr = (unsigned short *)ip;
memset(buff, 0, PIKE_BUFF_SIZE*sizeof(char));
int bsize;
int blen;

bsize = PIKE_BUFF_SIZE*sizeof(char);
memset(buff, 0, bsize);

DBG("pike:top:print_addr(iplen: %d, buffsize: %d)", iplen, buffsize);

if ( iplen == 4 ) {
inet_ntop(AF_INET, ip, buff, buffsize);
}
else if ( iplen == 16 ) {
} else if ( iplen == 16 ) {
inet_ntop(AF_INET6, ip, buff, buffsize);
}
else {
sprintf( buff, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
} else {
blen = snprintf(buff, bsize, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]),
htons(ipv6_ptr[3]),
htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]),
htons(ipv6_ptr[7]));
if(blen < 0 || blen >= bsize) {
LM_ERR("failed to print the address - reset it\n");
memset(buff, 0, bsize);
}
}

return buff;
Expand Down

0 comments on commit 7be06d4

Please sign in to comment.