[sr-dev] git:master:98249e2c: core: forward - clone outbound buffer for SREV_NET_DATA_OUT event

Daniel-Constantin Mierla miconda at gmail.com
Mon Aug 12 11:19:10 CEST 2019


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-08-12T11:14:38+02:00

core: forward - clone outbound buffer for SREV_NET_DATA_OUT event

- this event can execute a series of callbacks, leading to leak if only
the core function does pkg free
- GH #2027

---

Modified: src/core/forward.h

---

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

---

diff --git a/src/core/forward.h b/src/core/forward.h
index d039900aac..a629748686 100644
--- a/src/core/forward.h
+++ b/src/core/forward.h
@@ -136,9 +136,18 @@ static inline int msg_send_buffer(struct dest_info* dst, char* buf, int len,
 	outb.s = buf;
 	outb.len = len;
 	if(!(flags&1)) {
-		evp.data = (void*)&outb;
-		evp.dst = dst;
-		sr_event_exec(SREV_NET_DATA_OUT, &evp);
+		if(sr_event_enabled(SREV_NET_DATA_OUT)) {
+			outb.s = (char*)pkg_malloc(len + 1);
+			if(outb.s==NULL) {
+				LM_ERR("failed to clone outgoing buffer\n");
+				return -1;
+			}
+			memcpy(outb.s, buf, len);
+			outb.s[len] = '\0';
+			evp.data = (void*)&outb;
+			evp.dst = dst;
+			sr_event_exec(SREV_NET_DATA_OUT, &evp);
+		}
 	}
 
 	if(outb.s==NULL) {




More information about the sr-dev mailing list