[Asterisk-code-review] res pjsip messaging: Check URI type before deferencing (asterisk[master])

Sean Bright asteriskteam at digium.com
Tue Mar 21 08:31:07 CDT 2017


Sean Bright has uploaded a new change for review. ( https://gerrit.asterisk.org/5268 )

Change subject: res_pjsip_messaging: Check URI type before deferencing
......................................................................

res_pjsip_messaging: Check URI type before deferencing

We aren't validating that the URI we just parsed is a SIP/SIPS one before
trying to access the user, host, and port members of a possibly uninitialized
structure.

ASTERISK-26484 #close
Reported by: Vinod Dharashive

Change-Id: I476b5cc5f18a7713d0ee945374f2a1c164857d30
---
M res/res_pjsip_messaging.c
1 file changed, 9 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/68/5268/1

diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index 52fc16d..5c41a70 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -235,7 +235,15 @@
 	parsed_name_addr = (pjsip_name_addr *) pjsip_parse_uri(tdata->pool, from,
 		strlen(from), PJSIP_PARSE_URI_AS_NAMEADDR);
 	if (parsed_name_addr) {
-		pjsip_sip_uri *parsed_uri = pjsip_uri_get_uri(parsed_name_addr->uri);
+		pjsip_sip_uri *parsed_uri;
+
+		if (!PJSIP_URI_SCHEME_IS_SIP(parsed_name_addr->uri)
+				&& !PJSIP_URI_SCHEME_IS_SIPS(parsed_name_addr->uri)) {
+			ast_log(LOG_WARNING, "From address '%s' is not a valid SIP/SIPS URI\n", from);
+			return;
+		}
+
+		parsed_uri = pjsip_uri_get_uri(parsed_name_addr->uri);
 
 		if (pj_strlen(&parsed_name_addr->display)) {
 			pj_strdup(tdata->pool, &name_addr->display, &parsed_name_addr->display);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I476b5cc5f18a7713d0ee945374f2a1c164857d30
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>



More information about the asterisk-code-review mailing list