Skip to content

Commit 17558c5

Browse files
committed
mk_proxy(): Improve robustness
A lot of code which calls mk_proxy() for DNS resolution assumes that the "proxy->host->h_addr_list" array contains at least one value, e.g.: modules/drouting/routing.c +611: hostent2ip_addr(&pgw->ips[0], &proxy->host, proxy->addr_idx); modules/dispatcher/dispatch.c +281: hostent2ip_addr( &dp->ips[0], &proxy->host, proxy->addr_idx); This would cause a segfault immediately if h_addr_list contains 0 results (i.e. first value is a NULL pointer). As the overall intention is to resolve the hostname into at least 1 IP address, this patch changes mk_proxy() to return NULL on a successful query with 0 results. Credits to Jonathan Hulme for the report
1 parent 45dd0e5 commit 17558c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

proxy.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, unsigned short proto,
213213
LM_DBG("doing DNS lookup...\n");
214214
he = sip_resolvehost(name, &(p->port), &p->proto, is_sips,
215215
disable_dns_failover?0:&p->dn );
216-
if (he==0){
216+
if (!he || !he->h_addr_list[0]) {
217217
ser_error=E_BAD_ADDRESS;
218-
LM_CRIT("could not resolve hostname: \"%.*s\"\n", name->len, name->s);
218+
LM_CRIT("could not resolve hostname: \"%.*s\"%s\n",
219+
name->len, name->s, he ? " (0 results)" : "");
219220
pkg_free(p);
220221
goto error;
221222
}

0 commit comments

Comments
 (0)