[sr-dev] git:master:0e0cd2be: core: more checks when printing udp recv debug message

Daniel-Constantin Mierla miconda at gmail.com
Fri Dec 1 13:44:57 CET 2017


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-12-01T13:43:42+01:00

core: more checks when printing udp recv debug message

---

Modified: src/core/udp_server.c

---

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

---

diff --git a/src/core/udp_server.c b/src/core/udp_server.c
index 0392136385..b88d3d8f51 100644
--- a/src/core/udp_server.c
+++ b/src/core/udp_server.c
@@ -425,7 +425,9 @@ int udp_rcv_loop()
 	unsigned int fromlen;
 	struct receive_info ri;
 	sr_event_param_t evp = {0};
-	char printbuf[512];
+#define UDP_RCV_PRINTBUF_SIZE 512
+#define UDP_RCV_PRINT_LEN 100
+	char printbuf[UDP_RCV_PRINTBUF_SIZE];
 	int i;
 	int j;
 	int l;
@@ -472,20 +474,22 @@ int udp_rcv_loop()
 
 		if(is_printable(L_DBG) && len>10) {
 			j = 0;
-			for(i=0; i<len && i<100; i++) {
+			for(i=0; i<len && i<UDP_RCV_PRINT_LEN
+						&& j+8<UDP_RCV_PRINTBUF_SIZE; i++) {
 				if(isprint(buf[i])) {
 					printbuf[j++] = buf[i];
 				} else {
 					l = snprintf(printbuf+j, 6, " %02X ", buf[i]);
 					if(l<0 || l>=6) {
-						LM_ERR("print buffer building failed\n");
+						LM_ERR("print buffer building failed (%d/%d/%d)\n",
+								l, j, i);
 						goto error;
 					}
 					j += l;
 				}
 			}
-			LM_DBG("received on udp socket: (%d/%d) [[%.*s]]\n",
-					j, len, len, printbuf);
+			LM_DBG("received on udp socket: (%d/%d/%d) [[%.*s]]\n",
+					j, i, len, j, printbuf);
 		}
 		ri.src_su=*from;
 		su2ip_addr(&ri.src_ip, from);




More information about the sr-dev mailing list