Browse code

- applied dst_uri clone patch from Phil D'Amore. Fixes: msg->dst_uri not being cloned (see SER-53).

Andrei Pelinescu-Onciul authored on 04/07/2005 16:20:02
Showing 2 changed files
... ...
@@ -294,6 +294,9 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg, int *sip_msg_len )
294 294
 	/*the new uri (if any)*/
295 295
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
296 296
 		len+= ROUND4(org_msg->new_uri.len);
297
+	/*the dst uri (if any)*/
298
+	if (org_msg->dst_uri.s && org_msg->dst_uri.len)
299
+		len+= ROUND4(org_msg->dst_uri.len);
297 300
 	/*all the headers*/
298 301
 	for( hdr=org_msg->headers ; hdr ; hdr=hdr->next )
299 302
 	{
... ...
@@ -427,6 +430,13 @@ do { \
427 427
 		memcpy( p , org_msg->new_uri.s , org_msg->new_uri.len);
428 428
 		p += ROUND4(org_msg->new_uri.len);
429 429
 	}
430
+	/* dst_uri */
431
+	if (org_msg->dst_uri.s && org_msg->dst_uri.len)
432
+	{
433
+		new_msg->dst_uri.s = p;
434
+		memcpy( p , org_msg->dst_uri.s , org_msg->dst_uri.len);
435
+		p += ROUND4(org_msg->dst_uri.len);
436
+	}
430 437
 	/* message buffers(org and scratch pad) */
431 438
 	memcpy( p , org_msg->buf, org_msg->len);
432 439
 	/* ZT to be safer */
... ...
@@ -554,6 +554,18 @@ static inline int fake_req(struct sip_msg *faked_req,
554 554
 			faked_req->new_uri.len);
555 555
 		faked_req->new_uri.s[faked_req->new_uri.len]=0;
556 556
 	}
557
+	/* dst_uri can change ALSO!!! -- make a private copy */
558
+	if (shmem_msg->dst_uri.s!=0 && shmem_msg->dst_uri.len!=0) {
559
+		faked_req->dst_uri.s=pkg_malloc(shmem_msg->dst_uri.len+1);
560
+		if (!faked_req->dst_uri.s) {
561
+			LOG(L_ERR, "ERROR: fake_req: no uri/pkg mem\n");
562
+			goto error00;
563
+		}
564
+		faked_req->dst_uri.len=shmem_msg->dst_uri.len;
565
+		memcpy( faked_req->dst_uri.s, shmem_msg->dst_uri.s, 
566
+			faked_req->dst_uri.len);
567
+		faked_req->dst_uri.s[faked_req->dst_uri.len]=0;
568
+	}
557 569
 
558 570
 	return 1;
559 571
 error00:
... ...
@@ -569,6 +581,11 @@ void inline static free_faked_req(struct sip_msg *faked_req, struct cell *t)
569 569
 		faked_req->new_uri.s = 0;
570 570
 	}
571 571
 
572
+	if (faked_req->dst_uri.s) {
573
+		pkg_free(faked_req->dst_uri.s);
574
+		faked_req->dst_uri.s = 0;
575
+	}
576
+
572 577
 	/* free all types of lump that were added in failure handlers */
573 578
 	del_nonshm_lump( &(faked_req->add_rm) );
574 579
 	del_nonshm_lump( &(faked_req->body_lumps) );