Browse code

core: receive - check for required headers before routing blocks

Daniel-Constantin Mierla authored on 17/09/2021 06:22:09
Showing 1 changed files
... ...
@@ -421,9 +421,13 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
421 421
 	if(msg->first_line.type == SIP_REQUEST) {
422 422
 		ruri_mark_new(); /* ruri is usable for forking (not consumed yet) */
423 423
 		if(!IS_SIP(msg)) {
424
+			LM_DBG("handling non-sip request message\n");
424 425
 			if((ret = nonsip_msg_run_hooks(msg)) != NONSIP_MSG_ACCEPT) {
425
-				if(unlikely(ret == NONSIP_MSG_ERROR))
426
+				if(unlikely(ret == NONSIP_MSG_ERROR)) {
427
+					LM_DBG("failed handling non-sip request message\n");
426 428
 					goto error03;
429
+				}
430
+				LM_DBG("finished handling non-sip request message\n");
427 431
 				goto end; /* drop the message */
428 432
 			}
429 433
 		}
... ...
@@ -435,6 +439,14 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
435 439
 			STATS_BAD_MSG();
436 440
 			goto error02;
437 441
 		}
442
+		if(unlikely((msg->callid == 0) || (msg->cseq == 0) || (msg->from == 0)
443
+					|| (msg->to == 0))) {
444
+			/* no required headers -- send back error ? */
445
+			LOG(cfg_get(core, core_cfg, sip_parser_log),
446
+					"required headers not found in request\n");
447
+			STATS_BAD_MSG();
448
+			goto error02;
449
+		}
438 450
 /* check if necessary to add receive?->moved to forward_req */
439 451
 /* check for the alias stuff */
440 452
 #ifdef USE_TCP
... ...
@@ -526,6 +538,14 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
526 538
 			STATS_BAD_RPL();
527 539
 			goto error02;
528 540
 		}
541
+		if(unlikely((msg->callid == 0) || (msg->cseq == 0) || (msg->from == 0)
542
+					|| (msg->to == 0))) {
543
+			/* no required headers -- send back error ? */
544
+			LOG(cfg_get(core, core_cfg, sip_parser_log),
545
+					"required headers not found in reply\n");
546
+			STATS_BAD_RPL();
547
+			goto error02;
548
+		}
529 549
 
530 550
 		if(exectime) {
531 551
 			gettimeofday(&tvb, NULL);