]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_messaging: Check URI type before dereferencing
authorSean Bright <sean.bright@gmail.com>
Tue, 21 Mar 2017 13:26:28 +0000 (09:26 -0400)
committerSean Bright <sean.bright@gmail.com>
Tue, 21 Mar 2017 14:44:30 +0000 (10:44 -0400)
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.

Also update the MessageSend documentation to indicate what 'from' formats are
accepted.

ASTERISK-26484 #close
Reported by: Vinod Dharashive

Change-Id: I476b5cc5f18a7713d0ee945374f2a1c164857d30

main/message.c
res/res_pjsip_messaging.c

index 594853f3f5d6ac44f55a385fa2ebf0916ffd8f57..be0035d30d4c802473209be94db36f6390486b54 100644 (file)
@@ -127,8 +127,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        </parameter>
                        <parameter name="from" required="false">
                                <para>A From URI for the message if needed for the
-                               message technology being used to send this message.</para>
-                               <xi:include xpointer="xpointer(/docs/info[@name='MessageFromInfo'])" />
+                               message technology being used to send this message. This can be a
+                               SIP(S) URI, such as <literal>Alice &lt;sip:alice@atlanta.com&gt;</literal>,
+                               a string in the format <literal>alice@atlanta.com</literal>, or simply
+                               a username such as <literal>alice</literal>.</para>
                        </parameter>
                </syntax>
                <description>
index 835a383939d78203e0b5e5b235c9c77b348e10d9..8b465e00756c173b6fde64f7d440bfadeb60542a 100644 (file)
@@ -235,7 +235,15 @@ static void update_from(pjsip_tx_data *tdata, char *from)
        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);