Skip to content

Commit

Permalink
core: zero-ending ipv4 string in ip_addr2sbufz() like done for ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 6, 2022
1 parent 1dfeba4 commit 2eac6a0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/ip_addr.c
Expand Up @@ -237,7 +237,7 @@ int ip_addr2sbuf(struct ip_addr* ip, char* buff, int len)
}


/* same as ip_addr2sbuf, but with [ ] around IPv6 addresses */
/* same as ip_addr2sbuf, but with [ ] around IPv6 addresses and ending \0 */
int ip_addr2sbufz(struct ip_addr* ip, char* buff, int len)
{
char *p;
Expand All @@ -247,15 +247,15 @@ int ip_addr2sbufz(struct ip_addr* ip, char* buff, int len)
switch(ip->af){
case AF_INET6:
*p++ = '[';
sz = ip6tosbuf(ip->u.addr, p, len-2);
sz = ip6tosbuf(ip->u.addr, p, len-3);
p += sz;
*p++ = ']';
*p=0;
*p = '\0';
return sz + 2;
break;
case AF_INET:
return ip4tosbuf(ip->u.addr, buff, len);
break;
sz = ip4tosbuf(ip->u.addr, buff, len-1);
buff[sz] = '\0';
return sz;
default:
LM_CRIT("unknown address family %d\n", ip->af);
return 0;
Expand Down

0 comments on commit 2eac6a0

Please sign in to comment.