[Asterisk-code-review] res pjsip: Add missing NULL checks when using pjsip inv end ... (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Thu Jun 30 15:41:16 CDT 2016


Richard Mudgett has uploaded a new change for review.

  https://gerrit.asterisk.org/3131

Change subject: res_pjsip: Add missing NULL checks when using pjsip_inv_end_session().
......................................................................

res_pjsip: Add missing NULL checks when using pjsip_inv_end_session().

pjsip_inv_end_session() is documented as being able to return the
passed in tdata parameter set to NULL on success.

Change-Id: I09d53725c49b7183c41bfa1be3ff225f3a8d3047
---
M channels/chan_pjsip.c
M res/res_pjsip_refer.c
M res/res_pjsip_session.c
3 files changed, 10 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/31/3131/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 22f834d..5ad1174 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -1466,7 +1466,8 @@
 	pjsip_contact_hdr *contact;
 	pj_str_t tmp;
 
-	if (pjsip_inv_end_session(session->inv_session, 302, NULL, &packet) != PJ_SUCCESS) {
+	if (pjsip_inv_end_session(session->inv_session, 302, NULL, &packet) != PJ_SUCCESS
+		|| !packet) {
 		ast_log(LOG_WARNING, "Failed to redirect PJSIP session for channel %s\n",
 			ast_channel_name(session->channel));
 		message = AST_TRANSFER_FAILED;
@@ -2231,7 +2232,8 @@
 	ast_sip_session_add_datastore(session, datastore);
 
 	if (!(session->channel = chan_pjsip_new(session, AST_STATE_RING, session->exten, NULL, NULL, NULL, NULL))) {
-		if (pjsip_inv_end_session(session->inv_session, 503, NULL, &packet) == PJ_SUCCESS) {
+		if (pjsip_inv_end_session(session->inv_session, 503, NULL, &packet) == PJ_SUCCESS
+			&& packet) {
 			ast_sip_session_send_response(session, packet);
 		}
 
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index df54251..1043a1e 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -969,7 +969,8 @@
 		session->defer_terminate = 1;
 		ast_hangup(session->channel);
 
-		if (pjsip_inv_end_session(session->inv_session, response, NULL, &packet) == PJ_SUCCESS) {
+		if (pjsip_inv_end_session(session->inv_session, response, NULL, &packet) == PJ_SUCCESS
+			&& packet) {
 			ast_sip_session_send_response(session, packet);
 		}
 	} else {
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index eb95510..6287c17 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -2651,7 +2651,8 @@
 						}
 						if (tsx->status_code != 488) {
 							/* Other reinvite failures (except 488) result in destroying the session. */
-							if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS) {
+							if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS
+								&& tdata) {
 								ast_sip_session_send_request(session, tdata);
 							}
 						}
@@ -2664,7 +2665,8 @@
 						 * a cancelled call. Our role is to immediately send a BYE to end the
 						 * dialog.
 						 */
-						if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS) {
+						if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS
+							&& tdata) {
 							ast_sip_session_send_request(session, tdata);
 						}
 					}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09d53725c49b7183c41bfa1be3ff225f3a8d3047
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list