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

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2023-12-28T14:25:51+01:00

pike: use buffer size parameter in pike_top_print_addr()

---

Modified: src/modules/pike/pike_top.c

---

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

---

diff --git a/src/modules/pike/pike_top.c b/src/modules/pike/pike_top.c
index 0d9a5218e4c..a5126760a3a 100644
--- a/src/modules/pike/pike_top.c
+++ b/src/modules/pike/pike_top.c
@@ -41,33 +41,32 @@ struct TopListItem_t *pike_top_get_root()
 }
 
 char *pike_top_print_addr(
-               unsigned char *ip, int iplen, char *buff, int buffsize)
+               unsigned char *ip, int iplen, char *obuff, int obuffsize)
 {
        unsigned short *ipv6_ptr = (unsigned short *)ip;
-       int bsize;
        int blen;
 
-       bsize = PIKE_BUFF_SIZE * sizeof(char);
-       memset(buff, 0, bsize);
+       memset(obuff, 0, obuffsize);
 
-       DBG("pike:top:print_addr(iplen: %d, buffsize: %d)", iplen, buffsize);
+       DBG("address iplen: %d, buffsize: %d", iplen, obuffsize);
 
        if(iplen == 4) {
-               inet_ntop(AF_INET, ip, buff, buffsize);
+               inet_ntop(AF_INET, ip, obuff, obuffsize);
        } else if(iplen == 16) {
-               inet_ntop(AF_INET6, ip, buff, buffsize);
+               inet_ntop(AF_INET6, ip, obuff, obuffsize);
        } 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) {
+               blen = snprintf(obuff, obuffsize,
+                               "%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 >= obuffsize) {
                        LM_ERR("failed to print the address - reset it\n");
-                       memset(buff, 0, bsize);
+                       memset(obuff, 0, obuffsize);
                }
        }
 
-       return buff;
+       return obuff;
 }
 
 /* if you do not need global buffer, you can use this simpler call */

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to