[asterisk-commits] file: branch 12 r404737 - /branches/12/res/res_pjsip/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jan 3 11:25:48 CST 2014
Author: file
Date: Fri Jan 3 11:25:46 2014
New Revision: 404737
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404737
Log:
res_pjsip: Ensure more URI validation happens in pj threads.
Modified:
branches/12/res/res_pjsip/location.c
branches/12/res/res_pjsip/pjsip_configuration.c
Modified: branches/12/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/location.c?view=diff&rev=404737&r1=404736&r2=404737
==============================================================================
--- branches/12/res/res_pjsip/location.c (original)
+++ branches/12/res/res_pjsip/location.c Fri Jan 3 11:25:46 2014
@@ -225,11 +225,10 @@
return (ast_asprintf(buf, "%lu", contact->expiration_time.tv_sec) < 0) ? -1 : 0;
}
-/*! \brief Custom handler for permanent URIs */
-static int permanent_uri_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
-{
- struct ast_sip_aor *aor = obj;
- RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+/*! \brief Helper function which validates a permanent contact */
+static int permanent_contact_validate(void *data)
+{
+ const char *value = data;
pj_pool_t *pool;
pj_str_t contact_uri;
static const pj_str_t HCONTACT = { "Contact", 7 };
@@ -239,15 +238,27 @@
return -1;
}
- pj_strdup2_with_null(pool, &contact_uri, var->value);
+ pj_strdup2_with_null(pool, &contact_uri, value);
if (!pjsip_parse_hdr(pool, &HCONTACT, contact_uri.ptr, contact_uri.slen, NULL)) {
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ return -1;
+ }
+
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ return 0;
+}
+
+/*! \brief Custom handler for permanent URIs */
+static int permanent_uri_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+ struct ast_sip_aor *aor = obj;
+ RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+
+ if (ast_sip_push_task_synchronous(NULL, permanent_contact_validate, (char*)var->value)) {
ast_log(LOG_ERROR, "Permanent URI on aor '%s' with contact '%s' failed to parse\n",
ast_sorcery_object_get_id(aor), var->value);
- pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
- return -1;
- }
-
- pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ return -1;
+ }
if ((!aor->permanent_contacts && !(aor->permanent_contacts = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL))) ||
!(contact = ast_sorcery_alloc(ast_sip_get_sorcery(), "contact", NULL))) {
Modified: branches/12/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_configuration.c?view=diff&rev=404737&r1=404736&r2=404737
==============================================================================
--- branches/12/res/res_pjsip/pjsip_configuration.c (original)
+++ branches/12/res/res_pjsip/pjsip_configuration.c Fri Jan 3 11:25:46 2014
@@ -842,6 +842,29 @@
return persistent->endpoint;
}
+/*! \brief Helper function which validates an outbound proxy */
+static int outbound_proxy_validate(void *data)
+{
+ const char *proxy = data;
+ pj_pool_t *pool;
+ pj_str_t tmp;
+ static const pj_str_t ROUTE_HNAME = { "Route", 5 };
+
+ pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound Proxy Validation", 256, 256);
+ if (!pool) {
+ return -1;
+ }
+
+ pj_strdup2_with_null(pool, &tmp, proxy);
+ if (!pjsip_parse_hdr(pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL)) {
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ return -1;
+ }
+
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ return 0;
+}
+
/*! \brief Callback function for when an object is finalized */
static int sip_endpoint_apply_handler(const struct ast_sorcery *sorcery, void *obj)
{
@@ -851,26 +874,11 @@
return -1;
}
- if (!ast_strlen_zero(endpoint->outbound_proxy)) {
- pj_pool_t *pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound Proxy Validation", 256, 256);
- static const pj_str_t ROUTE_HNAME = { "Route", 5 };
- pj_str_t tmp;
-
- if (!pool) {
- ast_log(LOG_ERROR, "Could not allocate pool for outbound proxy validation on '%s'\n",
- ast_sorcery_object_get_id(endpoint));
- return -1;
- }
-
- pj_strdup2_with_null(pool, &tmp, endpoint->outbound_proxy);
- if (!pjsip_parse_hdr(pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL)) {
- ast_log(LOG_ERROR, "Invalid outbound proxy '%s' specified on endpoint '%s'\n",
- endpoint->outbound_proxy, ast_sorcery_object_get_id(endpoint));
- pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
- return -1;
- }
-
- pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ if (!ast_strlen_zero(endpoint->outbound_proxy) &&
+ ast_sip_push_task_synchronous(NULL, outbound_proxy_validate, (char*)endpoint->outbound_proxy)) {
+ ast_log(LOG_ERROR, "Invalid outbound proxy '%s' specified on endpoint '%s'\n",
+ endpoint->outbound_proxy, ast_sorcery_object_get_id(endpoint));
+ return -1;
}
return 0;
More information about the asterisk-commits
mailing list