Browse code

core: rely on msg->last_header to get the anchor inside sr_hdr_add()

- might fix GH #789

(cherry picked from commit 9483b5491f82dd18bbdaeee72fd43ec6e1fbfb8c)

Daniel-Constantin Mierla authored on 20/09/2016 09:40:07
Showing 1 changed files
... ...
@@ -743,13 +743,19 @@ int sr_hdr_add(sip_msg_t *msg, str *sname, str *sbody)
743 743
 	struct lump* anchor;
744 744
 	str h;
745 745
 
746
+	parse_headers(msg, HDR_EOH_F, 0);
747
+	if(msg->last_header == 0) {
748
+		LM_ERR("failed to parse headers\n");
749
+		return -1;
750
+	}
746 751
 	h.len = sname->len + 2 + sbody->len + CRLF_LEN;
747 752
 	h.s = (char*)pkg_malloc(h.len+1);
748 753
 	if(h.s == 0) {
749 754
 		LM_ERR("no more pkg\n");
750 755
 		return -1;
751 756
 	}
752
-	anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
757
+	anchor = anchor_lump(msg, msg->last_header->name.s + msg->last_header->len
758
+					- msg->buf, 0, 0);
753 759
 	if(anchor == 0)
754 760
 	{
755 761
 		LM_ERR("cannot get the anchor\n");