<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5976">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Fix crash with from_user containing invalid characters.<br><br>If the from_user field contains certain characters (like @, {, ^, etc.),<br>PJSIP will return a null value for the URI when attempting to parse it.<br>This causes a crash when trying to dial out through a trunk that contains<br>these invalid characters in its from_user field.<br><br>This change checks the configuration and ensures that an endpoint will<br>not be created if the from_user contains an invalid character. It also<br>adds a null check to the PJSIP URI parsing as a backup.<br><br>ASTERISK-27036 #close<br>Reported by: Maxim Vasilev<br><br>Change-Id: I0396fdb5080604e0bdf1277464d5c8a85db913d0<br>---<br>M res/res_pjsip.c<br>M res/res_pjsip/pjsip_configuration.c<br>2 files changed, 40 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip.c b/res/res_pjsip.c<br>index 8923540..6e389d5 100644<br>--- a/res/res_pjsip.c<br>+++ b/res/res_pjsip.c<br>@@ -3091,6 +3091,14 @@<br> /* Update the dialog with the new local URI, we do it afterwards so we can use the dialog pool for construction */<br> pj_strdup_with_null(dlg->pool, &dlg->local.info_str, &local_uri);<br> dlg->local.info->uri = pjsip_parse_uri(dlg->pool, dlg->local.info_str.ptr, dlg->local.info_str.slen, 0);<br>+ if (!dlg->local.info->uri) {<br>+ ast_log(LOG_ERROR,<br>+ "Could not parse URI '%s' for endpoint '%s'\n",<br>+ dlg->local.info_str.ptr, ast_sorcery_object_get_id(endpoint));<br>+ dlg->sess_count--;<br>+ pjsip_dlg_terminate(dlg);<br>+ return NULL;<br>+ }<br> <br> dlg->local.contact = pjsip_parse_hdr(dlg->pool, &HCONTACT, local_uri.ptr, local_uri.slen, NULL);<br> <br>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c<br>index 372b01b..ef3e05b 100644<br>--- a/res/res_pjsip/pjsip_configuration.c<br>+++ b/res/res_pjsip/pjsip_configuration.c<br>@@ -1148,6 +1148,37 @@<br> return 0;<br> }<br> <br>+static int from_user_handler(const struct aco_option *opt,<br>+ struct ast_variable *var, void *obj)<br>+{<br>+ struct ast_sip_endpoint *endpoint = obj;<br>+ /* Valid non-alphanumeric characters for URI */<br>+ char *valid_uri_marks = "-_.!~*`()";<br>+ const char *val;<br>+<br>+ for (val = var->value; *val; val++) {<br>+ if (!strchr(valid_uri_marks, *val) && !isdigit(*val) && !isalpha(*val)) {<br>+ ast_log(LOG_ERROR, "Error configuring endpoint '%s' - '%s' field "<br>+ "contains invalid character '%c'\n",<br>+ ast_sorcery_object_get_id(endpoint), var->name, *val);<br>+ return -1;<br>+ }<br>+ }<br>+<br>+ ast_string_field_set(endpoint, fromuser, var->value);<br>+<br>+ return 0;<br>+}<br>+<br>+static int from_user_to_str(const void *obj, const intptr_t *args, char **buf)<br>+{<br>+ const struct ast_sip_endpoint *endpoint = obj;<br>+<br>+ *buf = ast_strdup(endpoint->fromuser);<br>+<br>+ return 0;<br>+}<br>+<br> static int set_var_handler(const struct aco_option *opt,<br> struct ast_variable *var, void *obj)<br> {<br>@@ -1918,7 +1949,7 @@<br> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "cos_video", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, media.cos_video));<br> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "allow_subscribe", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.allow));<br> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "sub_min_expiry", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, subscription.minexpiry));<br>- ast_sorcery_object_field_register(sip_sorcery, "endpoint", "from_user", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, fromuser));<br>+ ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "from_user", "", from_user_handler, from_user_to_str, NULL, 0, 0);<br> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "from_domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, fromdomain));<br> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_from_user", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.fromuser));<br> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rtp_engine", "asterisk", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, media.rtp.engine));<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5976">change 5976</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/5976"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I0396fdb5080604e0bdf1277464d5c8a85db913d0 </div>
<div style="display:none"> Gerrit-Change-Number: 5976 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>