res_pjsip: Fix crash with from_user containing invalid characters.

If the from_user field contains certain characters (like @, {, ^, etc.),
PJSIP will return a null value for the URI when attempting to parse it.
This causes a crash when trying to dial out through a trunk that contains
these invalid characters in its from_user field.

This change checks the configuration and ensures that an endpoint will
not be created if the from_user contains an invalid character. It also
adds a null check to the PJSIP URI parsing as a backup.

ASTERISK-27036 #close
Reported by: Maxim Vasilev

Change-Id: I0396fdb5080604e0bdf1277464d5c8a85db913d0
This commit is contained in:
Benjamin Keith Ford
2017-07-07 11:19:13 -05:00
parent 5a894ff27e
commit 25e18bf514
2 changed files with 40 additions and 1 deletions

View File

@@ -3075,6 +3075,14 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
/* Update the dialog with the new local URI, we do it afterwards so we can use the dialog pool for construction */
pj_strdup_with_null(dlg->pool, &dlg->local.info_str, &local_uri);
dlg->local.info->uri = pjsip_parse_uri(dlg->pool, dlg->local.info_str.ptr, dlg->local.info_str.slen, 0);
if (!dlg->local.info->uri) {
ast_log(LOG_ERROR,
"Could not parse URI '%s' for endpoint '%s'\n",
dlg->local.info_str.ptr, ast_sorcery_object_get_id(endpoint));
dlg->sess_count--;
pjsip_dlg_terminate(dlg);
return NULL;
}
dlg->local.contact = pjsip_parse_hdr(dlg->pool, &HCONTACT, local_uri.ptr, local_uri.slen, NULL);