Prechádzať zdrojové kódy

dialog: safety checks for local cseq and contact vars

- avoid crash on systems not printing null string of length 0
- GH #1717
Daniel-Constantin Mierla 6 rokov pred
rodič
commit
46401e465d
1 zmenil súbory, kde vykonal 12 pridanie a 4 odobranie
  1. 12 4
      src/modules/dialog/dlg_handlers.c

+ 12 - 4
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);