Browse code

core: parse headers - check if anything was parsed

Daniel-Constantin Mierla authored on 08/04/2021 09:20:32
Showing 1 changed files
... ...
@@ -316,13 +316,14 @@ int parse_headers(struct sip_msg* const msg, const hdr_flags_t flags, const int
316 316
 	if (unlikely(next)) {
317 317
 		orig_flag = msg->parsed_flag;
318 318
 		msg->parsed_flag &= ~flags;
319
-	}else
319
+	} else {
320 320
 		orig_flag=0;
321
+	}
321 322
 
322 323
 #ifdef EXTRA_DEBUG
323 324
 	DBG("flags=%llx\n", (unsigned long long)flags);
324 325
 #endif
325
-	while( tmp<end && (flags & msg->parsed_flag) != flags){
326
+	while(tmp<end && (flags & msg->parsed_flag) != flags) {
326 327
 		prefetch_loc_r(tmp+64, 1);
327 328
 		hf=pkg_malloc(sizeof(struct hdr_field));
328 329
 		if (unlikely(hf==0)){
... ...
@@ -619,18 +620,25 @@ int parse_headers(struct sip_msg* const msg, const hdr_flags_t flags, const int
619 620
 #endif
620 621
 		tmp=rest;
621 622
 	}
623
+
622 624
 skip:
623 625
 	msg->unparsed=tmp;
626
+	if(msg->headers==NULL) {
627
+		/* nothing parsed - invalid input sip message */
628
+		goto error1;
629
+	}
624 630
 	/* restore original flags */
625 631
 	msg->parsed_flag |= orig_flag;
626 632
 	return 0;
627 633
 
628 634
 error:
629
-	ser_error=E_BAD_REQ;
630 635
 	if (hf) {
631 636
 		clean_hdr_field(hf);
632 637
 		pkg_free(hf);
633 638
 	}
639
+
640
+error1:
641
+	ser_error=E_BAD_REQ;
634 642
 	/* restore original flags */
635 643
 	msg->parsed_flag |= orig_flag;
636 644
 	return -1;