Module: kamailio
Branch: master
Commit: 46401e465d88495d510d2cb36dc36ec86978c53e
URL: 
https://github.com/kamailio/kamailio/commit/46401e465d88495d510d2cb36dc36ec86978c53e

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2018-11-30T16:31:22+01:00

dialog: safety checks for local cseq and contact vars

- avoid crash on systems not printing null string of length 0
- GH #1717

---

Modified: src/modules/dialog/dlg_handlers.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/46401e465d88495d510d2cb36dc36ec86978c53e.diff
Patch: 
https://github.com/kamailio/kamailio/commit/46401e465d88495d510d2cb36dc36ec86978c53e.patch

---

diff --git a/src/modules/dialog/dlg_handlers.c 
b/src/modules/dialog/dlg_handlers.c
index b6ce4d2bbd..a94dd641a4 100644
--- a/src/modules/dialog/dlg_handlers.c
+++ b/src/modules/dialog/dlg_handlers.c
@@ -200,7 +200,7 @@ int populate_leg_info( struct dlg_cell *dlg, struct sip_msg 
*msg,
        if (leg==DLG_CALLER_LEG) {
                if((!msg->cseq && (parse_headers(msg,HDR_CSEQ_F,0)<0 || 
!msg->cseq))
                        || !msg->cseq->parsed){
-                       LM_ERR("bad sip message or missing CSeq hdr :-/\n");
+                       LM_ERR("bad sip message or missing CSeq hdr\n");
                        goto error0;
                }
                cseq = (get_cseq(msg))->number;
@@ -208,6 +208,10 @@ int populate_leg_info( struct dlg_cell *dlg, struct 
sip_msg *msg,
                /* use the same as in request */
                cseq = dlg->cseq[DLG_CALLEE_LEG];
        }
+       if(cseq.s==NULL || cseq.len<=0) {
+               LM_ERR("empty CSeq number\n");
+               goto error0;
+       }
 
        /* extract the contact address */
        if 
(!msg->contact&&(parse_headers(msg,HDR_CONTACT_F,0)<0||!msg->contact)){
@@ -221,6 +225,10 @@ int populate_leg_info( struct dlg_cell *dlg, struct 
sip_msg *msg,
                goto error0;
        }
        contact = ((contact_body_t *)msg->contact->parsed)->contacts->uri;
+       if(contact.s==NULL || contact.len<=0) {
+               LM_ERR("empty contact uri\n");
+               goto error0;
+       }
 
        /* extract the record-route addresses */
        if (leg==DLG_CALLER_LEG) {
@@ -250,10 +258,10 @@ int populate_leg_info( struct dlg_cell *dlg, struct 
sip_msg *msg,
 
        LM_DBG("leg(%d) route_set [%.*s], contact [%.*s], cseq [%.*s]"
                        " and bind_addr [%.*s]\n",
-               leg, rr_set.len, rr_set.s, contact.len, contact.s,
-               cseq.len, cseq.s,
+               leg, rr_set.len, ZSW(rr_set.s), contact.len, ZSW(contact.s),
+               cseq.len, ZSW(cseq.s),
                msg->rcv.bind_address->sock_str.len,
-               msg->rcv.bind_address->sock_str.s);
+               ZSW(msg->rcv.bind_address->sock_str.s));
 
        if (dlg_set_leg_info( dlg, tag, &rr_set, &contact, &cseq, leg)!=0) {
                LM_ERR("dlg_set_leg_info failed (leg %d)\n", leg);


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to