<p>Benjamin Keith Ford has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5975">View Change</a></p><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, 37 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/75/5975/1</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 f05378c..7094d68 100644<br>--- a/res/res_pjsip.c<br>+++ b/res/res_pjsip.c<br>@@ -3071,6 +3071,12 @@<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>+ 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 cc12bff..26725da 100644<br>--- a/res/res_pjsip/pjsip_configuration.c<br>+++ b/res/res_pjsip/pjsip_configuration.c<br>@@ -1147,6 +1147,36 @@<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>+ char *val;<br>+<br>+ for (val = ast_strdup(var->value); *val; val++) {<br>+ if (!strchr(valid_uri_marks, *val) && !isdigit(*val) && !isalpha(*val)) {<br>+ return -1;<br>+ }<br>+ }<br>+<br>+ if (ast_string_field_set(endpoint, fromuser, ast_strdup(var->value)) == -1) {<br>+ return -1;<br>+ }<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>@@ -1912,7 +1942,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/5975">change 5975</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/5975"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I0396fdb5080604e0bdf1277464d5c8a85db913d0 </div>
<div style="display:none"> Gerrit-Change-Number: 5975 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>