[svn-commits] file: trunk r404738 - in /trunk: ./ res/res_pjsip/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jan 3 11:27:10 CST 2014


Author: file
Date: Fri Jan  3 11:27:08 2014
New Revision: 404738

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404738
Log:
res_pjsip: Ensure more URI validation happens in pj threads.
........

Merged revisions 404737 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/res/res_pjsip/location.c
    trunk/res/res_pjsip/pjsip_configuration.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Fri Jan  3 11:27:08 2014
@@ -1,1 +1,1 @@
-/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-403290,403292-403778,403781-404568,404581,404592,404605,404613,404652,404663,404676,404725
+/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-403290,403292-403778,403781-404568,404581,404592,404605,404613,404652,404663,404676,404725,404737

Modified: trunk/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/location.c?view=diff&rev=404738&r1=404737&r2=404738
==============================================================================
--- trunk/res/res_pjsip/location.c (original)
+++ trunk/res/res_pjsip/location.c Fri Jan  3 11:27:08 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: trunk/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_configuration.c?view=diff&rev=404738&r1=404737&r2=404738
==============================================================================
--- trunk/res/res_pjsip/pjsip_configuration.c (original)
+++ trunk/res/res_pjsip/pjsip_configuration.c Fri Jan  3 11:27:08 2014
@@ -835,6 +835,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)
 {
@@ -844,26 +867,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 svn-commits mailing list