205726d
From: Razvan Crainea <razvan@opensips.org>
205726d
Date: Wed, 13 Jun 2018 13:13:38 +0300
205726d
Subject: [PATCH] rtpproxy: fix adding the nortpproxy string
205726d
205726d
hack to properly add the nortpproxy string at the end of the body
205726d
205726d
(cherry picked from commit 79698b90d9a425e4460ea60647482348ba34cdce)
205726d
(cherry picked from commit 91b1197a779ffdf4644b4a02c6bf84baecd34a3d)
205726d
205726d
diff --git a/modules/rtpproxy/rtpproxy.c b/modules/rtpproxy/rtpproxy.c
205726d
index 6274667f6..7f32cfa99 100644
205726d
--- a/modules/rtpproxy/rtpproxy.c
205726d
+++ b/modules/rtpproxy/rtpproxy.c
205726d
@@ -4030,7 +4030,7 @@ force_rtp_proxy_body(struct sip_msg* msg, struct force_rtpp_args *args, pv_spec_
205726d
 	free_opts(&opts, &rep_opts, &pt_opts);
205726d
 
205726d
 	if (proxied == 0 && nortpproxy_str.len) {
205726d
-		cp = pkg_malloc((nortpproxy_str.len + CRLF_LEN) * sizeof(char));
205726d
+		cp = pkg_malloc((1 + nortpproxy_str.len + CRLF_LEN) * sizeof(char));
205726d
 		if (cp == NULL) {
205726d
 			LM_ERR("out of pkg memory\n");
205726d
 			return -1;
205726d
@@ -4040,15 +4040,19 @@ force_rtp_proxy_body(struct sip_msg* msg, struct force_rtpp_args *args, pv_spec_
205726d
 		while( cp1>args->body.s && !(*(cp1-1)=='\n' && *(cp1-2)=='\r') ) cp1--;
205726d
 		if (cp1==args->body.s) cp1=args->body.s + args->body.len;
205726d
 
205726d
-		anchor = anchor_lump(msg, cp1 - msg->buf, 0);
205726d
+		/* XXX: ugly hack to add a string _after_ the end of the body:
205726d
+		 * remove the last char and then add it in the new buffer */
205726d
+		cp1--;
205726d
+		cp[0] = *cp1;
205726d
+		anchor = del_lump(msg, cp1 - msg->buf, 1, 0);
205726d
 		if (anchor == NULL) {
205726d
-			LM_ERR("anchor_lump failed\n");
205726d
+			LM_ERR("del_lump failed\n");
205726d
 			pkg_free(cp);
205726d
 			return -1;
205726d
 		}
205726d
-		memcpy(cp, nortpproxy_str.s, nortpproxy_str.len);
205726d
-		memcpy(cp+nortpproxy_str.len , CRLF, CRLF_LEN);
205726d
-		if (insert_new_lump_before(anchor, cp, nortpproxy_str.len + CRLF_LEN, 0) == NULL) {
205726d
+		memcpy(cp+1, nortpproxy_str.s, nortpproxy_str.len);
205726d
+		memcpy(cp+1+nortpproxy_str.len , CRLF, CRLF_LEN);
205726d
+		if (insert_new_lump_before(anchor, cp, 1 + nortpproxy_str.len + CRLF_LEN, 0) == NULL) {
205726d
 			LM_ERR("insert_new_lump_after failed\n");
205726d
 			pkg_free(cp);
205726d
 			return -1;