Browse code

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().

Andrei Pelinescu-Onciul authored on 17/02/2010 19:46:47
Showing 2 changed files
... ...
@@ -736,12 +736,14 @@ int set_dst_uri(struct sip_msg* msg, str* uri)
736 736
 {
737 737
 	char* ptr;
738 738
 
739
-	if (!msg || !uri) {
739
+	if (unlikely(!msg || !uri)) {
740 740
 		LOG(L_ERR, "set_dst_uri: Invalid parameter value\n");
741 741
 		return -1;
742 742
 	}
743 743
 
744
-	if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
744
+	if (unlikely(uri->len == 0)) {
745
+		reset_dst_uri(msg);
746
+	}else if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
745 747
 		memcpy(msg->dst_uri.s, uri->s, uri->len);
746 748
 		msg->dst_uri.len = uri->len;
747 749
 	} else {
... ...
@@ -773,12 +775,14 @@ int set_path_vector(struct sip_msg* msg, str* path)
773 773
 {
774 774
 	char* ptr;
775 775
 
776
-	if (!msg || !path) {
776
+	if (unlikely(!msg || !path)) {
777 777
 		LM_ERR("invalid parameter value\n");
778 778
 		return -1;
779 779
 	}
780 780
 
781
-	if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
781
+	if (unlikely(path->len == 0)) {
782
+		reset_path_vector(msg);
783
+	} else if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
782 784
 		memcpy(msg->path_vec.s, path->s, path->len);
783 785
 		msg->path_vec.len = path->len;
784 786
 	} else {
... ...
@@ -513,6 +513,9 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
513 513
 	new_msg->add_rm = 0;
514 514
 	new_msg->body_lumps = 0;
515 515
 	new_msg->reply_lump = 0;
516
+	/* zero *uri.s, in case len is 0 but org_msg->*uris!=0 (just to be safe)*/
517
+	new_msg->new_uri.s = 0;
518
+	new_msg->dst_uri.s = 0;
516 519
 	/* new_uri */
517 520
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
518 521
 	{