[Asterisk-code-review] res pjsip: Only check transaction on transaction state events. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Sun May 22 11:12:19 CDT 2016


Joshua Colp has uploaded a new change for review.

  https://gerrit.asterisk.org/2896

Change subject: res_pjsip: Only check transaction on transaction state events.
......................................................................

res_pjsip: Only check transaction on transaction state events.

The send request callback function currently assumes that it
will only ever be called on transaction state changes. This is
not always true. If our own timer callback occurs we will call
the callback with a timer event instead of a transaction state
change event. In this case the transaction on the event is
invalid and accessing it will result in a crash.

ASTERISK-26049 #close

Change-Id: I623211c8533eb73056b0250b4580b49ad4174dfc
---
M res/res_pjsip.c
1 file changed, 39 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/96/2896/1

diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index c06b67e..bebe941 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -3513,46 +3513,48 @@
 	pjsip_rx_data *challenge;
 	struct ast_sip_supplement *supplement;
 
-	switch(e->body.tsx_state.type) {
-	case PJSIP_EVENT_TRANSPORT_ERROR:
-	case PJSIP_EVENT_TIMER:
-		/*
-		 * Check the request status on transport error or timeout. A transport
-		 * error can occur when a TCP socket closes and that can be the result
-		 * of a 503. Also we may need to failover on a timeout (408).
-		 */
-		if (check_request_status(req_data, e)) {
-			return;
-		}
-		break;
-	case PJSIP_EVENT_RX_MSG:
-		challenge = e->body.tsx_state.src.rdata;
-
-		/*
-		 * Call any supplements that want to know about a response
-		 * with any received data.
-		 */
-		AST_RWLIST_RDLOCK(&supplements);
-		AST_LIST_TRAVERSE(&supplements, supplement, next) {
-			if (supplement->incoming_response
-				&& does_method_match(&challenge->msg_info.cseq->method.name,
-					supplement->method)) {
-				supplement->incoming_response(req_data->endpoint, challenge);
-			}
-		}
-		AST_RWLIST_UNLOCK(&supplements);
-
-		if (check_request_status(req_data, e)) {
+	if (e->type == PJSIP_EVENT_TSX_STATE) {
+		switch(e->body.tsx_state.type) {
+		case PJSIP_EVENT_TRANSPORT_ERROR:
+		case PJSIP_EVENT_TIMER:
 			/*
-			 * Request with challenge response or failover sent.
-			 * Passed our req_data ref to the new request.
+			 * Check the request status on transport error or timeout. A transport
+			 * error can occur when a TCP socket closes and that can be the result
+			 * of a 503. Also we may need to failover on a timeout (408).
 			 */
-			return;
+			if (check_request_status(req_data, e)) {
+				return;
+			}
+			break;
+		case PJSIP_EVENT_RX_MSG:
+			challenge = e->body.tsx_state.src.rdata;
+
+			/*
+			 * Call any supplements that want to know about a response
+			 * with any received data.
+			 */
+			AST_RWLIST_RDLOCK(&supplements);
+			AST_LIST_TRAVERSE(&supplements, supplement, next) {
+				if (supplement->incoming_response
+					&& does_method_match(&challenge->msg_info.cseq->method.name,
+						supplement->method)) {
+					supplement->incoming_response(req_data->endpoint, challenge);
+				}
+			}
+			AST_RWLIST_UNLOCK(&supplements);
+
+			if (check_request_status(req_data, e)) {
+				/*
+				 * Request with challenge response or failover sent.
+				 * Passed our req_data ref to the new request.
+				 */
+				return;
+			}
+			break;
+		default:
+			ast_log(LOG_ERROR, "Unexpected PJSIP event %u\n", e->body.tsx_state.type);
+			break;
 		}
-		break;
-	default:
-		ast_log(LOG_ERROR, "Unexpected PJSIP event %u\n", e->body.tsx_state.type);
-		break;
 	}
 
 	if (req_data->callback) {

-- 
To view, visit https://gerrit.asterisk.org/2896
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I623211c8533eb73056b0250b4580b49ad4174dfc
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list