Browse Source

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 15 years ago
parent
commit
feb3478b19
2 changed files with 11 additions and 4 deletions
  1. 8 4
      parser/msg_parser.c
  2. 3 0
      sip_msg_clone.c

+ 8 - 4
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 {

+ 3 - 0
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)
 	{