[sr-dev] git:master:875bd485: core: kemi - safety check for lump archor for hdr operations

Daniel-Constantin Mierla miconda at gmail.com
Wed Apr 17 15:37:42 CEST 2019


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-04-17T15:31:12+02:00

core: kemi - safety check for lump archor for hdr operations

---

Modified: src/core/kemi.c

---

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

---

diff --git a/src/core/kemi.c b/src/core/kemi.c
index 039ba1557f..6a1d61af43 100644
--- a/src/core/kemi.c
+++ b/src/core/kemi.c
@@ -1679,7 +1679,8 @@ static int sr_kemi_hdr_append(sip_msg_t *msg, str *txt)
 	memcpy(hdr, txt->s, txt->len);
 	/* anchor after last header */
 	anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
-	if(insert_new_lump_before(anchor, hdr, txt->len, 0) == 0) {
+	if((anchor==NULL)
+			|| (insert_new_lump_before(anchor, hdr, txt->len, 0) == 0)) {
 		LM_ERR("can't insert lump\n");
 		pkg_free(hdr);
 		return -1;
@@ -1744,13 +1745,15 @@ static int sr_kemi_hdr_append_after(sip_msg_t *msg, str *txt, str *hname)
 		anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);
 	}
 
-	LM_DBG("append after [%.*s] the hf: [%.*s]\n", hname->len, hname->s,
-			txt->len, txt->s);
-	if(insert_new_lump_before(anchor, hdr, txt->len, 0) == 0) {
+	if((anchor==NULL)
+			|| (insert_new_lump_before(anchor, hdr, txt->len, 0) == 0)) {
 		LM_ERR("can't insert lump\n");
 		pkg_free(hdr);
 		return -1;
 	}
+	LM_DBG("appended after [%.*s] the hf: [%.*s]\n", hname->len, hname->s,
+			txt->len, txt->s);
+
 	return 1;
 }
 
@@ -1871,7 +1874,8 @@ static int sr_kemi_hdr_insert(sip_msg_t *msg, str *txt)
 	memcpy(hdr, txt->s, txt->len);
 	/* anchor before first header */
 	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0, 0);
-	if(insert_new_lump_before(anchor, hdr, txt->len, 0) == 0) {
+	if((anchor==NULL)
+			|| (insert_new_lump_before(anchor, hdr, txt->len, 0) == 0)) {
 		LM_ERR("can't insert lump\n");
 		pkg_free(hdr);
 		return -1;
@@ -1934,13 +1938,15 @@ static int sr_kemi_hdr_insert_before(sip_msg_t *msg, str *txt, str *hname)
 	} else { /* before hf */
 		anchor = anchor_lump(msg, hf->name.s - msg->buf, 0, 0);
 	}
-	LM_DBG("insert before [%.*s] the hf: %.*s\n", hname->len, hname->s,
-			txt->len, txt->s);
-	if(insert_new_lump_before(anchor, hdr, txt->len, 0) == 0) {
+	if((anchor==NULL)
+			|| (insert_new_lump_before(anchor, hdr, txt->len, 0) == 0)) {
 		LM_ERR("can't insert lump\n");
 		pkg_free(hdr);
 		return -1;
 	}
+	LM_DBG("inserted before [%.*s] the hf: %.*s\n", hname->len, hname->s,
+			txt->len, txt->s);
+
 	return 1;
 }
 




More information about the sr-dev mailing list