From 809d5e84f3423ab8165650d923acb0e246cbd006 Mon Sep 17 00:00:00 2001 From: HALX99 Date: Fri, 16 Apr 2021 08:34:02 +0800 Subject: [PATCH] Fix can't get dns server on macos and ios (#401) If DNS configuration didn't include search domains on MacOS (or iOS) it would throw an error instead of ignoring. Fix By: @halx99 --- src/lib/ares_init.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/ares_init.c b/src/lib/ares_init.c index 0903ac6e..0917dce2 100644 --- a/src/lib/ares_init.c +++ b/src/lib/ares_init.c @@ -1665,17 +1665,18 @@ static int init_by_resolv_conf(ares_channel channel) int entries = 0; while ((entries < MAXDNSRCH) && res.dnsrch[entries]) entries++; - - channel->domains = ares_malloc(entries * sizeof(char *)); - if (!channel->domains) { - status = ARES_ENOMEM; - } else { - int i; - channel->ndomains = entries; - for (i = 0; i < channel->ndomains; ++i) { - channel->domains[i] = ares_strdup(res.dnsrch[i]); - if (!channel->domains[i]) - status = ARES_ENOMEM; + if(entries) { + channel->domains = ares_malloc(entries * sizeof(char *)); + if (!channel->domains) { + status = ARES_ENOMEM; + } else { + int i; + channel->ndomains = entries; + for (i = 0; i < channel->ndomains; ++i) { + channel->domains[i] = ares_strdup(res.dnsrch[i]); + if (!channel->domains[i]) + status = ARES_ENOMEM; + } } } }