[sr-dev] git:master:2eac6a0c: core: zero-ending ipv4 string in ip_addr2sbufz() like done for ipv6

Daniel-Constantin Mierla miconda at gmail.com
Thu Apr 7 08:27:47 CEST 2022


Module: kamailio
Branch: master
Commit: 2eac6a0c2f2dd7c8831ef65fa9d92b88a79d23af
URL: https://github.com/kamailio/kamailio/commit/2eac6a0c2f2dd7c8831ef65fa9d92b88a79d23af

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-04-06T20:36:26+02:00

core: zero-ending ipv4 string in ip_addr2sbufz() like done for ipv6

---

Modified: src/core/ip_addr.c

---

Diff:  https://github.com/kamailio/kamailio/commit/2eac6a0c2f2dd7c8831ef65fa9d92b88a79d23af.diff
Patch: https://github.com/kamailio/kamailio/commit/2eac6a0c2f2dd7c8831ef65fa9d92b88a79d23af.patch

---

diff --git a/src/core/ip_addr.c b/src/core/ip_addr.c
index cb07a3e60d..77ac233eee 100644
--- a/src/core/ip_addr.c
+++ b/src/core/ip_addr.c
@@ -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;
@@ -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;




More information about the sr-dev mailing list