core: receive - check for required headers before routing blocks
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 17 Sep 2021 06:22:09 +0000 (08:22 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 17 Sep 2021 06:22:09 +0000 (08:22 +0200)
src/core/receive.c

index f3b31fe..b3e6aee 100644 (file)
@@ -421,9 +421,13 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
        if(msg->first_line.type == SIP_REQUEST) {
                ruri_mark_new(); /* ruri is usable for forking (not consumed yet) */
                if(!IS_SIP(msg)) {
        if(msg->first_line.type == SIP_REQUEST) {
                ruri_mark_new(); /* ruri is usable for forking (not consumed yet) */
                if(!IS_SIP(msg)) {
+                       LM_DBG("handling non-sip request message\n");
                        if((ret = nonsip_msg_run_hooks(msg)) != NONSIP_MSG_ACCEPT) {
                        if((ret = nonsip_msg_run_hooks(msg)) != NONSIP_MSG_ACCEPT) {
-                               if(unlikely(ret == NONSIP_MSG_ERROR))
+                               if(unlikely(ret == NONSIP_MSG_ERROR)) {
+                                       LM_DBG("failed handling non-sip request message\n");
                                        goto error03;
                                        goto error03;
+                               }
+                               LM_DBG("finished handling non-sip request message\n");
                                goto end; /* drop the message */
                        }
                }
                                goto end; /* drop the message */
                        }
                }
@@ -435,6 +439,14 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
                        STATS_BAD_MSG();
                        goto error02;
                }
                        STATS_BAD_MSG();
                        goto error02;
                }
+               if(unlikely((msg->callid == 0) || (msg->cseq == 0) || (msg->from == 0)
+                                       || (msg->to == 0))) {
+                       /* no required headers -- send back error ? */
+                       LOG(cfg_get(core, core_cfg, sip_parser_log),
+                                       "required headers not found in request\n");
+                       STATS_BAD_MSG();
+                       goto error02;
+               }
 /* check if necessary to add receive?->moved to forward_req */
 /* check for the alias stuff */
 #ifdef USE_TCP
 /* check if necessary to add receive?->moved to forward_req */
 /* check for the alias stuff */
 #ifdef USE_TCP
@@ -526,6 +538,14 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
                        STATS_BAD_RPL();
                        goto error02;
                }
                        STATS_BAD_RPL();
                        goto error02;
                }
+               if(unlikely((msg->callid == 0) || (msg->cseq == 0) || (msg->from == 0)
+                                       || (msg->to == 0))) {
+                       /* no required headers -- send back error ? */
+                       LOG(cfg_get(core, core_cfg, sip_parser_log),
+                                       "required headers not found in reply\n");
+                       STATS_BAD_RPL();
+                       goto error02;
+               }
 
                if(exectime) {
                        gettimeofday(&tvb, NULL);
 
                if(exectime) {
                        gettimeofday(&tvb, NULL);