[sr-dev] git:5.1:a874ac69: core: more checks when printing udp recv debug message

Daniel-Constantin Mierla miconda at gmail.com
Fri Dec 1 14:26:19 CET 2017


Module: kamailio
Branch: 5.1
Commit: a874ac693bdeaaf913f3a260f0ed0294ea3668f2
URL: https://github.com/kamailio/kamailio/commit/a874ac693bdeaaf913f3a260f0ed0294ea3668f2

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-12-01T14:25:40+01:00

core: more checks when printing udp recv debug message

(cherry picked from commit 0e0cd2be0c77f84575526a39c6e3baa199e18d02)

---

Modified: src/core/udp_server.c

---

Diff:  https://github.com/kamailio/kamailio/commit/a874ac693bdeaaf913f3a260f0ed0294ea3668f2.diff
Patch: https://github.com/kamailio/kamailio/commit/a874ac693bdeaaf913f3a260f0ed0294ea3668f2.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