Browse code

- fixed the problem in message cloner reported by Ingo Wolfsberger <iwolfsberger@gmx.net>

Jan Janak authored on 18/05/2005 17:10:45
Showing 1 changed files
... ...
@@ -227,8 +227,8 @@ static inline struct auth_body* auth_body_cloner(char* new_buf, char *org_buf, s
227 227
 }
228 228
 
229 229
 
230
-static inline void clone_authorized_hooks(struct sip_msg* new,
231
-														struct sip_msg* old)
230
+static inline int clone_authorized_hooks(struct sip_msg* new,
231
+					 struct sip_msg* old)
232 232
 {
233 233
 	struct hdr_field* ptr, *new_ptr, *hook1, *hook2;
234 234
 	char stop = 0;
... ...
@@ -244,12 +244,20 @@ static inline void clone_authorized_hooks(struct sip_msg* new,
244 244
 
245 245
 	while(ptr) {
246 246
 		if (ptr == hook1) {
247
+			if (!new->authorization || !new->authorization->parsed) {
248
+				LOG(L_CRIT, "BUG: Error in message cloner (authorization)\n");
249
+				return -1;
250
+			}				
247 251
 			((struct auth_body*)new->authorization->parsed)->authorized =
248 252
 				new_ptr;
249 253
 			stop |= 1;
250 254
 		}
251 255
 		
252 256
 		if (ptr == hook2) {
257
+			if (!new->proxy_auth || !new->proxy_auth->parsed) {
258
+				LOG(L_CRIT, "BUG: Error in message cloner (proxy_auth)\n");
259
+				return -1;
260
+			}
253 261
 			((struct auth_body*)new->proxy_auth->parsed)->authorized =
254 262
 				new_ptr;
255 263
 			stop |= 2;
... ...
@@ -260,6 +268,7 @@ static inline void clone_authorized_hooks(struct sip_msg* new,
260 260
 		ptr = ptr->next;
261 261
 		new_ptr = new_ptr->next;
262 262
 	}
263
+	return 0;
263 264
 }
264 265
 
265 266
 
... ...
@@ -520,14 +529,14 @@ do { \
520 520
 				((struct cseq_body*)new_hdr->parsed)->method.s =
521 521
 					translate_pointer(new_msg->buf ,org_msg->buf,
522 522
 					((struct cseq_body*)hdr->parsed)->method.s );
523
-				new_msg->cseq = new_hdr;
523
+				if (new_msg->cseq == 0) new_msg->cseq = new_hdr;
524 524
 				break;
525 525
 			case HDR_TO_T:
526 526
 			case HDR_FROM_T:
527 527
 				if (hdr->type == HDR_TO_T) {
528
-					new_msg->to = new_hdr;
528
+					if (new_msg->to == 0) new_msg->to = new_hdr;
529 529
 				} else {
530
-					new_msg->from = new_hdr;
530
+					if (new_msg->from == 0) new_msg->from = new_hdr;
531 531
 				}
532 532
 				/* From header might be unparsed */
533 533
 				if (!hdr->parsed) break;
... ...
@@ -570,83 +579,129 @@ do { \
570 570
 				}
571 571
 				break;
572 572
 			case HDR_CALLID_T:
573
-				new_msg->callid = new_hdr;
573
+				if (new_msg->callid == 0) {
574
+					new_msg->callid = new_hdr;
575
+				}
574 576
 				break;
575 577
 			case HDR_CONTACT_T:
576
-				new_msg->contact = new_hdr;
578
+				if (new_msg->contact == 0) {
579
+					new_msg->contact = new_hdr;
580
+				}
577 581
 				break;
578 582
 			case HDR_MAXFORWARDS_T:
579
-				new_msg->maxforwards = new_hdr;
583
+				if (new_msg->maxforwards == 0) {
584
+					new_msg->maxforwards = new_hdr;
585
+				}
580 586
 				break;
581 587
 			case HDR_ROUTE_T:
582
-				new_msg->route = new_hdr;
588
+				if (new_msg->route == 0) {
589
+					new_msg->route = new_hdr;
590
+				}
583 591
 				break;
584 592
 			case HDR_RECORDROUTE_T:
585
-				new_msg->record_route = new_hdr;
593
+				if (new_msg->record_route == 0) {
594
+					new_msg->record_route = new_hdr;
595
+				}
586 596
 				break;
587 597
 			case HDR_CONTENTTYPE_T:
588
-				new_msg->content_type = new_hdr;
589
-				new_msg->content_type->parsed = hdr->parsed;
598
+				if (new_msg->content_type == 0) {
599
+					new_msg->content_type = new_hdr;
600
+					new_msg->content_type->parsed = hdr->parsed;
601
+				}
590 602
 				break;
591 603
 			case HDR_CONTENTLENGTH_T:
592
-				new_msg->content_length = new_hdr;
593
-				new_msg->content_length->parsed = hdr->parsed;
604
+				if (new_msg->content_length == 0) {
605
+					new_msg->content_length = new_hdr;
606
+					new_msg->content_length->parsed = hdr->parsed;
607
+				}
594 608
 				break;
595 609
 			case HDR_AUTHORIZATION_T:
596
-				new_msg->authorization = new_hdr;
610
+				if (new_msg->authorization == 0) {
611
+					new_msg->authorization = new_hdr;
612
+				}
597 613
 				if (hdr->parsed) {
598 614
 					new_hdr->parsed = auth_body_cloner(new_msg->buf ,
599 615
 						org_msg->buf , (struct auth_body*)hdr->parsed , &p);
600 616
 				}
601 617
 				break;
602 618
 			case HDR_EXPIRES_T:
603
-				new_msg->expires = new_hdr;
619
+				if (new_msg->expires == 0) {
620
+					new_msg->expires = new_hdr;
621
+				}
604 622
 				break;
605 623
 			case HDR_PROXYAUTH_T:
606
-				new_msg->proxy_auth = new_hdr;
624
+				if (new_msg->proxy_auth == 0) {
625
+					new_msg->proxy_auth = new_hdr;
626
+				}
607 627
 				if (hdr->parsed) {
608 628
 					new_hdr->parsed = auth_body_cloner(new_msg->buf ,
609 629
 						org_msg->buf , (struct auth_body*)hdr->parsed , &p);
610 630
 				}
611 631
 				break;
612 632
 			case HDR_SUPPORTED_T:
613
-				new_msg->supported = new_hdr;
633
+				if (new_msg->supported == 0) {
634
+					new_msg->supported = new_hdr;
635
+				}
614 636
 				break;
615 637
 			case HDR_PROXYREQUIRE_T:
616
-				new_msg->proxy_require = new_hdr;
638
+				if (new_msg->proxy_require == 0) {
639
+					new_msg->proxy_require = new_hdr;
640
+				}
617 641
 				break;
618 642
 			case HDR_UNSUPPORTED_T:
619
-				new_msg->unsupported = new_hdr;
643
+				if (new_msg->unsupported == 0) {
644
+					new_msg->unsupported = new_hdr;
645
+				}
620 646
 				break;
621 647
 			case HDR_ALLOW_T:
622
-				new_msg->allow = new_hdr;	
648
+				if (new_msg->allow == 0) {
649
+					new_msg->allow = new_hdr;
650
+				}
623 651
 				break;
624 652
 			case HDR_EVENT_T:
625
-				new_msg->event = new_hdr;
653
+				if (new_msg->event == 0) {
654
+					new_msg->event = new_hdr;
655
+				}
626 656
 				break;
627 657
 			case HDR_ACCEPT_T:
628
-				new_msg->accept = new_hdr;
658
+				if (new_msg->accept == 0) {
659
+					new_msg->accept = new_hdr;
660
+				}
629 661
 				break;
630 662
 			case HDR_ACCEPTLANGUAGE_T:
631
-				new_msg->accept_language = new_hdr;
663
+				if (new_msg->accept_language == 0) {
664
+					new_msg->accept_language = new_hdr;
665
+				}
632 666
 				break;
633 667
 			case HDR_ORGANIZATION_T:
634
-				new_msg->organization = new_hdr;
668
+				if (new_msg->organization == 0) {
669
+					new_msg->organization = new_hdr;
670
+				}
635 671
 				break;
636 672
 			case HDR_PRIORITY_T:
637
-				new_msg->priority = new_hdr;
673
+				if (new_msg->priority == 0) {
674
+					new_msg->priority = new_hdr;
675
+				}
638 676
 				break;
639 677
 			case HDR_SUBJECT_T:
640
-				new_msg->subject = new_hdr;
678
+				if (new_msg->priority == 0) {
679
+					new_msg->subject = new_hdr;
680
+				}
641 681
 				break;
642 682
 			case HDR_USERAGENT_T:
643
-				new_msg->user_agent = new_hdr;
683
+				if (new_msg->user_agent == 0) {
684
+					new_msg->user_agent = new_hdr;
685
+				}
644 686
 				break;
645 687
 			case HDR_ACCEPTDISPOSITION_T:
646
-				new_msg->accept_disposition = new_hdr;
688
+				if (new_msg->accept_disposition == 0) {
689
+					new_msg->accept_disposition = new_hdr;
690
+				}
647 691
 				break;
648 692
 			case HDR_CONTENTDISPOSITION_T:
649
-				new_msg->content_disposition = new_hdr;
693
+				if (new_msg->content_disposition == 0) {
694
+					new_msg->content_disposition = new_hdr;
695
+				}
650 696
 				break;
651 697
 			default:
652 698
 				/* ignore the rest*/
... ...
@@ -719,7 +774,10 @@ do { \
719 719
 		rpl_lump_anchor = &((*rpl_lump_anchor)->next);
720 720
 	}
721 721
 
722
-	clone_authorized_hooks(new_msg, org_msg);
722
+	if (clone_authorized_hooks(new_msg, org_msg) < 0) {
723
+		shm_free(new_msg);
724
+		return 0;
725
+	}
723 726
 
724 727
 	return new_msg;
725 728
 }