[asterisk-commits] lmadsen: tag 1.8.4.1 r320221 - in /tags/1.8.4.1: ChangeLog channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 20 14:28:28 CDT 2011


Author: lmadsen
Date: Fri May 20 14:28:16 2011
New Revision: 320221

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=320221
Log:
Merge changes for issue #19182 and update the ChangeLog.

Modified:
    tags/1.8.4.1/ChangeLog
    tags/1.8.4.1/channels/chan_sip.c

Modified: tags/1.8.4.1/ChangeLog
URL: http://svnview.digium.com/svn/asterisk/tags/1.8.4.1/ChangeLog?view=diff&rev=320221&r1=320220&r2=320221
==============================================================================
--- tags/1.8.4.1/ChangeLog (original)
+++ tags/1.8.4.1/ChangeLog Fri May 20 14:28:16 2011
@@ -26,6 +26,36 @@
 	handling.
 
 	(closes issue 0018951)
+
+	r319142 | mnicholson | 2011-05-16 10:53:27 -0500 (Mon, 16 May 2011) | 8 lines
+
+	Make sure tcptls_session exists before dereferencing it.
+
+	(closes issue 0019192)
+	Reported by: stknob
+	Patches:
+	      10-tcptls-unreachable-peer-segfault.patch uploaded by Chainsaw
+	      (license 723)
+	      Tested by: vois, Chainsaw
+
+	r320180 | mnicholson | 2011-05-20 13:48:46 -0500 (Fri, 20 May 2011) |
+	16 lines
+
+	This commit modifies the way polling is done on TLS sockets.
+
+	Because of the buffering the TLS layer does, polling is unreliable. If
+	poll is called while there is data waiting to be read in the TLS layer but not
+	at the network layer, the messaging processing engine will not proceed until
+	something else writes data to the socket, which may not occur. This change
+	modifies the logic around TLS sockets to only poll after a failed read on a
+	non-blocking socket. This way we know that there is no data waiting to be read from
+	the buffering layer.
+
+	(closes issue #19182)
+	Reported by: st
+	Patches:
+	      ssl-poll-fix3.diff uploaded by mnicholson (license 96)
+	      Tested by: mnicholson
 
 2011-05-09  Leif Madsen <lmadsen at digium.com>
 

Modified: tags/1.8.4.1/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/tags/1.8.4.1/channels/chan_sip.c?view=diff&rev=320221&r1=320220&r2=320221
==============================================================================
--- tags/1.8.4.1/channels/chan_sip.c (original)
+++ tags/1.8.4.1/channels/chan_sip.c Fri May 20 14:28:16 2011
@@ -2472,7 +2472,7 @@
 */
 static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session)
 {
-	int res, cl, timeout = -1, authenticated = 0, flags;
+	int res, cl, timeout = -1, authenticated = 0, flags, after_poll = 0, need_poll = 1;
 	time_t start;
 	struct sip_request req = { 0, } , reqcpy = { 0, };
 	struct sip_threadinfo *me = NULL;
@@ -2579,6 +2579,7 @@
 		/* handle the socket event, check for both reads from the socket fd,
 		 * and writes from alert_pipe fd */
 		if (fds[0].revents) { /* there is data on the socket to be read */
+			after_poll = 1;
 
 			fds[0].revents = 0;
 
@@ -2619,22 +2620,35 @@
 					timeout = -1;
 				}
 
-				res = ast_wait_for_input(tcptls_session->fd, timeout);
-				if (res < 0) {
-					ast_debug(2, "SIP %s server :: ast_wait_for_input returned %d\n", tcptls_session->ssl ? "SSL": "TCP", res);
-					goto cleanup;
-				} else if (res == 0) {
-					/* timeout */
-					ast_debug(2, "SIP %s server timed out\n", tcptls_session->ssl ? "SSL": "TCP");
-					goto cleanup;
+				/* special polling behavior is required for TLS
+				 * sockets because of the buffering done in the
+				 * TLS layer */
+				if (!tcptls_session->ssl || need_poll) {
+					need_poll = 0;
+					after_poll = 1;
+					res = ast_wait_for_input(tcptls_session->fd, timeout);
+					if (res < 0) {
+						ast_debug(2, "SIP TCP server :: ast_wait_for_input returned %d\n", res);
+						goto cleanup;
+					} else if (res == 0) {
+						/* timeout */
+						ast_debug(2, "SIP TCP server timed out\n");
+						goto cleanup;
+					}
 				}
 
 				ast_mutex_lock(&tcptls_session->lock);
 				if (!fgets(buf, sizeof(buf), tcptls_session->f)) {
 					ast_mutex_unlock(&tcptls_session->lock);
-					goto cleanup;
+					if (after_poll) {
+						goto cleanup;
+					} else {
+						need_poll = 1;
+						continue;
+					}
 				}
 				ast_mutex_unlock(&tcptls_session->lock);
+				after_poll = 0;
 				if (me->stop) {
 					 goto cleanup;
 				}
@@ -2653,30 +2667,40 @@
 						}
 
 						if (timeout == 0) {
-							ast_debug(2, "SIP %s server timed out", tcptls_session->ssl ? "SSL": "TCP");
+							ast_debug(2, "SIP %s server timed out\n", tcptls_session->ssl ? "SSL": "TCP");
 							goto cleanup;
 						}
 					} else {
 						timeout = -1;
 					}
 
-					res = ast_wait_for_input(tcptls_session->fd, timeout);
-					if (res < 0) {
-						ast_debug(2, "SIP %s server :: ast_wait_for_input returned %d\n", tcptls_session->ssl ? "SSL": "TCP", res);
-						goto cleanup;
-					} else if (res == 0) {
-						/* timeout */
-						ast_debug(2, "SIP %s server timed out", tcptls_session->ssl ? "SSL": "TCP");
-						goto cleanup;
+					if (!tcptls_session->ssl || need_poll) {
+						need_poll = 0;
+						after_poll = 1;
+						res = ast_wait_for_input(tcptls_session->fd, timeout);
+						if (res < 0) {
+							ast_debug(2, "SIP TCP server :: ast_wait_for_input returned %d\n", res);
+							goto cleanup;
+						} else if (res == 0) {
+							/* timeout */
+							ast_debug(2, "SIP TCP server timed out\n");
+							goto cleanup;
+						}
 					}
 
 					ast_mutex_lock(&tcptls_session->lock);
 					if (!(bytes_read = fread(buf, 1, MIN(sizeof(buf) - 1, cl), tcptls_session->f))) {
 						ast_mutex_unlock(&tcptls_session->lock);
-						goto cleanup;
+						if (after_poll) {
+							goto cleanup;
+						} else {
+							need_poll = 1;
+							continue;
+						}
 					}
 					buf[bytes_read] = '\0';
 					ast_mutex_unlock(&tcptls_session->lock);
+					after_poll = 0;
 					if (me->stop) {
 						goto cleanup;
 					}




More information about the asterisk-commits mailing list