[sr-dev] git:master:febccd68: core: dns - safety checks for port and proto pointers

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 18 09:16:19 CEST 2017


Module: kamailio
Branch: master
Commit: febccd6808d0729fca1bbf452d43c253ca79249a
URL: https://github.com/kamailio/kamailio/commit/febccd6808d0729fca1bbf452d43c253ca79249a

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-18T09:09:29+02:00

core: dns - safety checks for port and proto pointers

---

Modified: src/core/dns_cache.c
Modified: src/core/resolve.c

---

Diff:  https://github.com/kamailio/kamailio/commit/febccd6808d0729fca1bbf452d43c253ca79249a.diff
Patch: https://github.com/kamailio/kamailio/commit/febccd6808d0729fca1bbf452d43c253ca79249a.patch

---

diff --git a/src/core/dns_cache.c b/src/core/dns_cache.c
index e37361ffbb..3558a5ffcb 100644
--- a/src/core/dns_cache.c
+++ b/src/core/dns_cache.c
@@ -2560,7 +2560,7 @@ struct hostent* dns_srv_get_he(str* name, unsigned short* port, int flags)
 		rr_name.len=((struct srv_rdata*)rr->rdata)->name_len;
 		if ((he=dns_get_he(&rr_name, flags))!=0){
 				/* success, at least one good ip found */
-				*port=((struct srv_rdata*)rr->rdata)->port;
+				if(port) *port=((struct srv_rdata*)rr->rdata)->port;
 				goto end;
 		}
 		rr_no++; /* try from the next record, the current one was not good */
@@ -3213,9 +3213,9 @@ inline static int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
 	int ret;
 	struct hostent* he;
 	size_t i,list_len;
-	char origproto;
+	char origproto = 0;
 
-	origproto = *proto;
+	if(proto) origproto = *proto;
 	if (dns_hash==0){ /* not init => use normal, non-cached version */
 		LM_WARN("called before dns cache initialization\n");
 		h->srv=h->a=0;
@@ -3344,7 +3344,7 @@ inline static int dns_naptr_sip_resolve(struct dns_srv_handle* h,  str* name,
 	int ret;
 
 	ret=-E_DNS_NO_NAPTR;
-	origproto=*proto;
+	if(proto) origproto=*proto;
 	if (dns_hash==0){ /* not init => use normal, non-cached version */
 		LM_WARN("called before dns cache initialization\n");
 		h->srv=h->a=0;
@@ -3399,7 +3399,7 @@ inline static int dns_naptr_sip_resolve(struct dns_srv_handle* h,  str* name,
 								from previous dns_srv_sip_resolve calls */
 	}
 naptr_not_found:
-	*proto=origproto;
+	if(proto) *proto=origproto;
 	return dns_srv_sip_resolve(h, name, ip, port, proto, flags);
 }
 #endif /* USE_NAPTR */
diff --git a/src/core/resolve.c b/src/core/resolve.c
index 3d574182e9..7073a9a9e6 100644
--- a/src/core/resolve.c
+++ b/src/core/resolve.c
@@ -1597,7 +1597,7 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
 	naptr_bmp_t tried_bmp; /* tried bitmap */
 	char origproto;
 
-	origproto = *proto;
+	if(proto) origproto = *proto;
 	naptr_head=0;
 	he=0;
 	if (name->len >= MAX_DNS_NAME) {
@@ -1634,7 +1634,7 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
 #endif
 	}
 	/* fallback to srv lookup */
-	*proto = origproto;
+	if(proto) *proto = origproto;
 	he=no_naptr_srv_sip_resolvehost(name,port,proto);
 	/* fallback all the way down to A/AAAA */
 	if (he==0) {




More information about the sr-dev mailing list