[sr-dev] git:master:64303a93: nathelper: add_rcv_param() - do not enclose to double quotes if URI param

Daniel-Constantin Mierla miconda at gmail.com
Wed Jan 24 11:56:08 CET 2018


Module: kamailio
Branch: master
Commit: 64303a9398afe65d65cf35489c04e725689a5da2
URL: https://github.com/kamailio/kamailio/commit/64303a9398afe65d65cf35489c04e725689a5da2

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-01-24T11:52:47+01:00

nathelper: add_rcv_param() - do not enclose to double quotes if URI param

- restrict adding the param to contact URI only for UDP, otherwise a
second transport parameter appears in the URI
- do not enclose the value in double quotes when adding as URI param, it
is not allowed by SIP specs grammar
- discussed on GH PR #1203

---

Modified: src/modules/nathelper/nathelper.c

---

Diff:  https://github.com/kamailio/kamailio/commit/64303a9398afe65d65cf35489c04e725689a5da2.diff
Patch: https://github.com/kamailio/kamailio/commit/64303a9398afe65d65cf35489c04e725689a5da2.patch

---

diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c
index 168bae09cc..a45588a50d 100644
--- a/src/modules/nathelper/nathelper.c
+++ b/src/modules/nathelper/nathelper.c
@@ -2110,9 +2110,13 @@ static int ki_add_rcv_param(sip_msg_t *msg, int upos)
 	struct lump *anchor;
 	char *param;
 	str uri;
-	int hdr_param;
 
-	hdr_param = (upos)?0:1;
+	if(upos) {
+		if(msg->rcv.proto != PROTO_UDP) {
+			LM_ERR("adding received parameter to Contact URI works only for UDP\n");
+			return -1;
+		}
+	}
 
 	if(create_rcv_uri(&uri, msg) < 0) {
 		return -1;
@@ -2129,16 +2133,20 @@ static int ki_add_rcv_param(sip_msg_t *msg, int upos)
 			return -1;
 		}
 		memcpy(param, RECEIVED, RECEIVED_LEN);
-		param[RECEIVED_LEN] = '\"';
-		memcpy(param + RECEIVED_LEN + 1, uri.s, uri.len);
-		param[RECEIVED_LEN + 1 + uri.len] = '\"';
-
-		if(hdr_param) {
-			/* add the param as header param */
-			anchor = anchor_lump(msg, c->name.s + c->len - msg->buf, 0, 0);
+		if(upos) {
+			memcpy(param + RECEIVED_LEN, uri.s, uri.len);
 		} else {
+			param[RECEIVED_LEN] = '\"';
+			memcpy(param + RECEIVED_LEN + 1, uri.s, uri.len);
+			param[RECEIVED_LEN + 1 + uri.len] = '\"';
+		}
+
+		if(upos) {
 			/* add the param as uri param */
 			anchor = anchor_lump(msg, c->uri.s + c->uri.len - msg->buf, 0, 0);
+		} else {
+			/* add the param as header param */
+			anchor = anchor_lump(msg, c->name.s + c->len - msg->buf, 0, 0);
 		}
 		if(anchor == NULL) {
 			LM_ERR("anchor_lump failed\n");
@@ -2146,9 +2154,8 @@ static int ki_add_rcv_param(sip_msg_t *msg, int upos)
 			return -1;
 		}
 
-		if(insert_new_lump_after(
-				   anchor, param, RECEIVED_LEN + 1 + uri.len + 1, 0)
-				== 0) {
+		if(insert_new_lump_after(anchor, param,
+					RECEIVED_LEN + 1 + uri.len + 1 - ((upos)?2:0), 0) == 0) {
 			LM_ERR("insert_new_lump_after failed\n");
 			pkg_free(param);
 			return -1;




More information about the sr-dev mailing list