[Asterisk-cvs] asterisk/channels chan_sip.c,1.850,1.851

kpfleming kpfleming
Tue Sep 13 22:16:39 CDT 2005


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv31357/channels

Modified Files:
	chan_sip.c 
Log Message:
make RTP handling errors less likely to crash Asterisk (issue #5172)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.850
retrieving revision 1.851
diff -u -d -r1.850 -r1.851
--- chan_sip.c	14 Sep 2005 01:53:06 -0000	1.850
+++ chan_sip.c	14 Sep 2005 02:15:14 -0000	1.851
@@ -2660,8 +2660,10 @@
 		if (relaxdtmf)
 			ast_dsp_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
 	}
-	tmp->fds[0] = ast_rtp_fd(i->rtp);
-	tmp->fds[1] = ast_rtcp_fd(i->rtp);
+	if (i->rtp) {
+		tmp->fds[0] = ast_rtp_fd(i->rtp);
+		tmp->fds[1] = ast_rtcp_fd(i->rtp);
+	}
 	if (i->vrtp) {
 		tmp->fds[2] = ast_rtp_fd(i->vrtp);
 		tmp->fds[3] = ast_rtcp_fd(i->vrtp);
@@ -2830,6 +2832,12 @@
 	/* Retrieve audio/etc from channel.  Assumes p->lock is already held. */
 	struct ast_frame *f;
 	static struct ast_frame null_frame = { AST_FRAME_NULL, };
+	
+	if (!p->rtp) {
+		/* We have no RTP allocated for this channel */
+		return &null_frame;
+	}
+
 	switch(ast->fdno) {
 	case 0:
 		f = ast_rtp_read(p->rtp);	/* RTP Audio */
@@ -2940,8 +2948,8 @@
 		p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
 		if (videosupport)
 			p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
-		if (!p->rtp) {
-			ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno));
+		if (!p->rtp || (videosupport && !p->vrtp)) {
+			ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n", videosupport ? "and video" : "", strerror(errno));
 			ast_mutex_destroy(&p->lock);
 			if (p->chanvars) {
 				ast_variables_destroy(p->chanvars);
@@ -3261,6 +3269,11 @@
 	int debug=sip_debug_test_pvt(p);
 	struct ast_channel *bridgepeer = NULL;
 
+	if (!p->rtp) {
+		ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n");
+		return -1;
+	}
+
 	/* Update our last rtprx when we receive an SDP, too */
 	time(&p->lastrtprx);
 	time(&p->lastrtptx);
@@ -4316,8 +4329,11 @@
 		return -1;
 	}
 	respprep(&resp, p, msg, req);
-	ast_rtp_offered_from_local(p->rtp, 0);
-	add_sdp(&resp, p);
+	if (p->rtp) {
+		ast_rtp_offered_from_local(p->rtp, 0);
+		add_sdp(&resp, p);
+		ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid);
+	}
 	return send_response(p, &resp, retrans, seqno);
 }
 
@@ -4636,7 +4652,7 @@
 			}
 		}
 	}
-	if (sdp) {
+	if (sdp && p->rtp) {
 		ast_rtp_offered_from_local(p->rtp, 1);
 		add_sdp(&req, p);
 	} else {




More information about the svn-commits mailing list