[sr-dev] git:kamailio_3.0: core: avoid non-null 0-length dst_uri, ruris and path

Andrei Pelinescu-Onciul andrei at iptel.org
Wed Feb 17 21:12:16 CET 2010


Module: sip-router
Branch: kamailio_3.0
Commit: 832a6bf53562ca492ecbbee86b5445ffee00c883
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=832a6bf53562ca492ecbbee86b5445ffee00c883

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Wed Feb 17 20:46:47 2010 +0100

core: avoid non-null 0-length dst_uri,  ruris and path

- a dst_uri or ruri that has 0 length should be equivalent to also
having a null corresponding char* pointer.  sip_msg_shm_clone()
will now clone this type of uris to (0,0).
- set_dst_uri() called with "" (a 0-length non-zero string) is now
  equivalent to reset_dst_uri().
- set_path_vector() called with "" is now equivalent with
  reset_path_vector().
(cherry picked from commit feb3478b19452fe096f33364e6a59ec57c93efbe)

---

 parser/msg_parser.c |   12 ++++++++----
 sip_msg_clone.c     |    3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index 48f666c..0c56211 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -736,12 +736,14 @@ int set_dst_uri(struct sip_msg* msg, str* uri)
 {
 	char* ptr;
 
-	if (!msg || !uri) {
+	if (unlikely(!msg || !uri)) {
 		LOG(L_ERR, "set_dst_uri: Invalid parameter value\n");
 		return -1;
 	}
 
-	if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
+	if (unlikely(uri->len == 0)) {
+		reset_dst_uri(msg);
+	}else if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
 		memcpy(msg->dst_uri.s, uri->s, uri->len);
 		msg->dst_uri.len = uri->len;
 	} else {
@@ -773,12 +775,14 @@ int set_path_vector(struct sip_msg* msg, str* path)
 {
 	char* ptr;
 
-	if (!msg || !path) {
+	if (unlikely(!msg || !path)) {
 		LM_ERR("invalid parameter value\n");
 		return -1;
 	}
 
-	if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
+	if (unlikely(path->len == 0)) {
+		reset_path_vector(msg);
+	} else if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
 		memcpy(msg->path_vec.s, path->s, path->len);
 		msg->path_vec.len = path->len;
 	} else {
diff --git a/sip_msg_clone.c b/sip_msg_clone.c
index 979e46f..7308942 100644
--- a/sip_msg_clone.c
+++ b/sip_msg_clone.c
@@ -513,6 +513,9 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
 	new_msg->add_rm = 0;
 	new_msg->body_lumps = 0;
 	new_msg->reply_lump = 0;
+	/* zero *uri.s, in case len is 0 but org_msg->*uris!=0 (just to be safe)*/
+	new_msg->new_uri.s = 0;
+	new_msg->dst_uri.s = 0;
 	/* new_uri */
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
 	{




More information about the sr-dev mailing list