summaryrefslogtreecommitdiff
path: root/third-party/pjproject/patches/0013-r5559-svn-backport-Fix-to-resolve-DNS-SRV-crashes.patch
blob: dc03cbc209b31017e7c76578db8677277767ff27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
From d9d52f005f6d0242ea84e7c59ad6b25f052c8485 Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Mon, 20 Feb 2017 12:05:32 -0600
Subject: [PATCH 3/5] r5559 svn backport Fix to resolve DNS SRV crashes.

Re #1994 (misc): Don't try to resolve a DNS SRV query that is already considered resolved.
Thanks to Richard Mudgett for the patch.

srv_resolver.c: Don't try to send query if already considered resolved.

* In resolve_hostnames() don't try to resolve a query that is already
considered resolved.

* In resolve_hostnames() fix DNS typo in comments.

* In build_server_entries() move a common expression assigning to cnt
earlier.

sip_transport.c: Fix tdata object name to actually contain the pointer.

It helps if the logs referencing a tdata object buffer actually have
a name that includes the correct pointer as part of the name.  Also
since the tdata has its own pool it helps if any logs referencing the
pool have the same name as the tdata object.  This change brings tdata
logging in line with how tsx objects are named.
---
 pjlib-util/src/pjlib-util/srv_resolver.c | 18 +++++++++++++-----
 pjsip/src/pjsip/sip_transport.c          |  3 ++-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/pjlib-util/src/pjlib-util/srv_resolver.c b/pjlib-util/src/pjlib-util/srv_resolver.c
index 8a2f7e1..84ad3f6 100644
--- a/pjlib-util/src/pjlib-util/srv_resolver.c
+++ b/pjlib-util/src/pjlib-util/srv_resolver.c
@@ -407,8 +407,9 @@ static void build_server_entries(pj_dns_srv_async_query *query_job,
     for (i=0; i<query_job->srv_cnt; ++i) {
 	pj_in_addr addr;
 	pj_in6_addr addr6;
+	unsigned cnt = query_job->srv[i].addr_cnt;
 
-	if (query_job->srv[i].addr_cnt != 0) {
+	if (cnt != 0) {
 	    /* IP address already resolved */
 	    continue;
 	}
@@ -417,7 +418,6 @@ static void build_server_entries(pj_dns_srv_async_query *query_job,
 	    pj_inet_pton(pj_AF_INET(), &query_job->srv[i].target_name,
 			 &addr) == PJ_SUCCESS)
 	{
-	    unsigned cnt = query_job->srv[i].addr_cnt;
 	    pj_sockaddr_init(pj_AF_INET(), &query_job->srv[i].addr[cnt],
 			     NULL, query_job->srv[i].port);
 	    query_job->srv[i].addr[cnt].ipv4.sin_addr = addr;
@@ -427,7 +427,6 @@ static void build_server_entries(pj_dns_srv_async_query *query_job,
 		   pj_inet_pton(pj_AF_INET6(), &query_job->srv[i].target_name,
 				&addr6) == PJ_SUCCESS)
 	{
-	    unsigned cnt = query_job->srv[i].addr_cnt;
 	    pj_sockaddr_init(pj_AF_INET6(), &query_job->srv[i].addr[cnt],
 			     NULL, query_job->srv[i].port);
 	    query_job->srv[i].addr[cnt].ipv6.sin6_addr = addr6;
@@ -480,6 +479,15 @@ static pj_status_t resolve_hostnames(pj_dns_srv_async_query *query_job)
     for (i=0; i<query_job->srv_cnt; ++i) {
 	struct srv_target *srv = &query_job->srv[i];
 
+	if (srv->addr_cnt != 0) {
+	    /*
+	     * This query is already counted as resolved because of the
+	     * additional records in the SRV response or the target name
+	     * is an IP address exception in build_server_entries().
+	     */
+	    continue;
+	}
+
 	PJ_LOG(5, (query_job->objname, 
 		   "Starting async DNS A query_job for %.*s",
 		   (int)srv->target_name.slen, 
@@ -493,7 +501,7 @@ static pj_status_t resolve_hostnames(pj_dns_srv_async_query *query_job)
 
 	status = PJ_SUCCESS;
 
-	/* Start DNA A record query */
+	/* Start DNS A record query */
 	if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA_ONLY) == 0)
 	{
 	    if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA) != 0) {
@@ -511,7 +519,7 @@ static pj_status_t resolve_hostnames(pj_dns_srv_async_query *query_job)
 						 &srv->common, &srv->q_a);
 	}
 
-	/* Start DNA AAAA record query */
+	/* Start DNS AAAA record query */
 	if (status == PJ_SUCCESS &&
 	    (query_job->option & PJ_DNS_SRV_RESOLVE_AAAA) != 0)
 	{
diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index d672a6d..6dd14d1 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -422,7 +422,8 @@ PJ_DEF(pj_status_t) pjsip_tx_data_create( pjsip_tpmgr *mgr,
     tdata = PJ_POOL_ZALLOC_T(pool, pjsip_tx_data);
     tdata->pool = pool;
     tdata->mgr = mgr;
-    pj_memcpy(tdata->obj_name, pool->obj_name, PJ_MAX_OBJ_NAME);
+    pj_ansi_snprintf(tdata->obj_name, sizeof(tdata->obj_name), "tdta%p", tdata);
+    pj_memcpy(pool->obj_name, tdata->obj_name, sizeof(pool->obj_name));
 
     status = pj_atomic_create(tdata->pool, 0, &tdata->ref_cnt);
     if (status != PJ_SUCCESS) {
-- 
2.7.4