[Asterisk-code-review] chan sip.c: chan sip unstable with TLS after asterisk start... (asterisk[15.5])

David Hajek asteriskteam at digium.com
Mon Sep 3 09:59:37 CDT 2018


David Hajek has uploaded this change for review. ( https://gerrit.asterisk.org/10039


Change subject: chan_sip.c:  chan_sip unstable with TLS after asterisk start or reloads
......................................................................

chan_sip.c:  chan_sip unstable with TLS after asterisk start or reloads

Fixes random asterisk crash on start or reload with TLS phones.

ASTERISK-28034  #close
Reported-by: David Hajek

Change-Id: I2a859f97dc80c348e2fa56e918214ee29521c4ac
---
M channels/chan_sip.c
1 file changed, 8 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/39/10039/1

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index ad06422..2d3f885 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2574,12 +2574,15 @@
 	}
 
 	ao2_lock(tcptls_session);
-
-	if (!(th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")) ||
+	
+	// check stream isn't NULL
+	if (    (!tcptls_session->stream) ||
+		!(th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")) ||
 		!(packet = ao2_alloc(sizeof(*packet), tcptls_packet_destructor)) ||
 		!(packet->data = ast_str_create(len))) {
 		goto tcptls_write_setup_error;
 	}
+	
 
 	/* goto tcptls_write_error should _NOT_ be used beyond this point */
 	ast_str_set(&packet->data, 0, "%s", (char *) buf);
@@ -3097,7 +3100,7 @@
 
 			if (read(me->alert_pipe[0], &alert, sizeof(alert)) == -1) {
 				ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno));
-				continue;
+				goto cleanup; // read failed, usually Bad file descriptor, so go to cleanup to be safe
 			}
 
 			switch (alert) {
@@ -3116,9 +3119,11 @@
 					}
 					ao2_t_ref(packet, -1, "tcptls packet sent, this is no longer needed");
 				}
+				else goto cleanup; //frame_q is empty, nothing to write, go to cleanup to be safe
 				break;
 			default:
 				ast_log(LOG_ERROR, "Unknown tcptls thread alert '%u'\n", alert);
+				goto cleanup; // weird things, go to cleanup to be safe
 			}
 		}
 	}

-- 
To view, visit https://gerrit.asterisk.org/10039
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15.5
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a859f97dc80c348e2fa56e918214ee29521c4ac
Gerrit-Change-Number: 10039
Gerrit-PatchSet: 1
Gerrit-Owner: David Hajek <david.hajek at daktela.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180903/11482a81/attachment.html>


More information about the asterisk-code-review mailing list