Commit d378c68d authored by David 'Digit' Turner's avatar David 'Digit' Turner
Browse files

Fix spurious DNS lookups in the C library.

The problem was that the 'defdname' field of res_state structure
was not properly initialized in __res_vinit(). This field is used
to store the default domain name, which is normally build from
calling gethostname() (see line 549 of res_init.c).

Unfortunately, in the typical Android case, gethostname() returns
an error (the hostname is configured) and a random stack string is
used later to build the DNS search list (see lines 556+ in res_init.c)

For the sake of illustration, let's say the search list is set to
a random value like 'xWLK'.

The end result is that when trying to result an unknown domain name
(e.g. 'www.ptn'), the query fails then the resolver tries to make a
new query with the DNS search list path(s) appended (e.g. 'www.ptn.xWLK').

The patch simply initializes 'defdname' to an empty string to avoid
this when the net.dns.search system property is not set.

Also contains whitespace/formatting fixes
parent d7ed1ae9
master froyo froyo-release gingerbread gingerbread-mr4-release gingerbread-release ics-factoryrom-2-release ics-mr0 ics-mr0-release ics-mr1 ics-mr1-release ics-plus-aosp idea133 idea133-weekly-release jb-dev jb-mr0-release jb-mr1-dev jb-mr1-dev-plus-aosp jb-mr1-release jb-mr1.1-cts-dev jb-mr1.1-dev jb-mr1.1-dev-plus-aosp jb-mr1.1-release jb-mr2-cts-dev jb-mr2-dev jb-mr2-release jb-mr2.0-release jb-mr2.0.0-release jb-release kitkat-cts-dev kitkat-dev kitkat-mr1-release kitkat-mr1.1-release kitkat-mr2-release kitkat-mr2.1-release kitkat-mr2.2-release kitkat-release kitkat-wear l-preview lollipop-cts-dev lollipop-dev lollipop-mr1-cts-dev lollipop-mr1-dev lollipop-mr1-fi-release lollipop-mr1-release lollipop-mr1-wfc-release lollipop-release lollipop-wear-release marshmallow-cts-dev marshmallow-dev marshmallow-release master-soong studio-1.1-release tools_r20 tools_r21 tools_r22 tools_r22.2 android-wear-5.1.1_r1 android-wear-5.1.0_r1 android-wear-5.0.0_r1 android-sdk-support_r11 android-sdk-adt_r20 android-sdk-adt_r16.0.1 android-sdk-4.4.2_r1.0.1 android-sdk-4.4.2_r1 android-sdk-4.0.3_r1 android-sdk-4.0.3-tools_r1 android-m-preview android-m-preview-2 android-m-preview-1 android-l-preview_r2 android-cts-verifier-4.0.3_r1 android-cts-verifier-4.0_r1 android-cts-6.0_r1 android-cts-5.1_r3 android-cts-5.1_r2 android-cts-5.1_r1 android-cts-5.0_r3 android-cts-4.4_r4 android-cts-4.4_r1 android-cts-4.2_r2 android-cts-4.2_r1 android-cts-4.1_r4 android-cts-4.1_r2 android-cts-4.1_r1 android-cts-4.0.3_r2 android-cts-4.0.3_r1 android-cts-4.0_r1 android-cts-2.3_r12 android-cts-2.3_r11 android-cts-2.3_r10 android-cts-2.2_r8 android-6.0.0_r1 android-5.1.1_r24 android-5.1.1_r23 android-5.1.1_r22 android-5.1.1_r20 android-5.1.1_r19 android-5.1.1_r18 android-5.1.1_r17 android-5.1.1_r16 android-5.1.1_r15 android-5.1.1_r14 android-5.1.1_r13 android-5.1.1_r12 android-5.1.1_r10 android-5.1.1_r9 android-5.1.1_r8 android-5.1.1_r7 android-5.1.1_r6 android-5.1.1_r5 android-5.1.1_r4 android-5.1.1_r3 android-5.1.1_r2 android-5.1.1_r1 android-5.1.0_r5 android-5.1.0_r4 android-5.1.0_r3 android-5.1.0_r1 android-5.0.2_r3 android-5.0.2_r1 android-5.0.1_r1 android-5.0.0_r7 android-5.0.0_r6 android-5.0.0_r5.1 android-5.0.0_r5 android-5.0.0_r4 android-5.0.0_r3 android-5.0.0_r2 android-5.0.0_r1 android-4.4.4_r2.0.1 android-4.4.4_r2 android-4.4.4_r1.0.1 android-4.4.4_r1 android-4.4.3_r1.1.0.1 android-4.4.3_r1.1 android-4.4.3_r1.0.1 android-4.4.3_r1 android-4.4.2_r2.0.1 android-4.4.2_r2 android-4.4.2_r1.0.1 android-4.4.2_r1 android-4.4.1_r1.0.1 android-4.4.1_r1 android-4.4w_r1 android-4.4_r1.2.0.1 android-4.4_r1.2 android-4.4_r1.1.0.1 android-4.4_r1.1 android-4.4_r1.0.1 android-4.4_r1 android-4.4_r0.9 android-4.4_r0.8 android-4.4_r0.7 android-4.3.1_r1 android-4.3_r3.1 android-4.3_r3 android-4.3_r2.3 android-4.3_r2.2 android-4.3_r2.1 android-4.3_r2 android-4.3_r1.1 android-4.3_r1 android-4.3_r0.9.1 android-4.3_r0.9 android-4.2.2_r1.2 android-4.2.2_r1.1 android-4.2.2_r1 android-4.2.1_r1.2 android-4.2.1_r1.1 android-4.2.1_r1 android-4.2_r1 android-4.1.2_r2.1 android-4.1.2_r2 android-4.1.2_r1 android-4.1.1_r6.1 android-4.1.1_r6 android-4.1.1_r5 android-4.1.1_r4 android-4.1.1_r3 android-4.1.1_r2 android-4.1.1_r1.1 android-4.1.1_r1 android-4.0.4_r2.1 android-4.0.4_r2 android-4.0.4_r1.2 android-4.0.4_r1.1 android-4.0.4_r1 android-4.0.3_r1.1 android-4.0.3_r1 android-4.0.2_r1 android-4.0.1_r1.2 android-4.0.1_r1.1 android-4.0.1_r1 android-2.3.7_r1 android-2.3.6_r1 android-2.3.6_r0.9 android-2.3.5_r1 android-2.3.4_r1 android-2.3.4_r0.9 android-2.3.3_r1.1 android-2.3.3_r1 android-2.3.2_r1 android-2.3.1_r1 android-2.3_r1 android-2.2.3_r2.1 android-2.2.3_r2 android-2.2.3_r1 android-2.2.2_r1 android-2.2.1_r2 android-2.2.1_r1 android-2.2_r1.3 android-2.2_r1.2 android-2.2_r1.1 android-2.2_r1
No related merge requests found
......@@ -76,6 +76,10 @@ Differences between current and Android 2.1:
- <time.h>: Fix timezone management implementation to properly update
'tm_gmtoff' field in 'struct tm' structure.
- DNS: get rid of spurious random DNS queries when trying to resolve
an unknown domain name. Due to an initialization bug, a random DNS search
list was generated for each thread is net.dns.search is not defined.
-------------------------------------------------------------------------------
Differences between Android 2.1 and 2.0.1:
......
......@@ -251,7 +251,7 @@ _bprint( char* p, char* end, const char* format, ... )
return p;
va_start(args, format);
n = snprintf( p, avail, format, args);
n = vsnprintf( p, avail, format, args);
va_end(args);
/* certain C libraries return -1 in case of truncation */
......
......@@ -198,6 +198,8 @@ int load_domain_search_list(res_state statp) {
if (pp > statp->dnsrch)
return 1;
}
statp->defdname[0] = '\0'; /* no default domain name on Android */
statp->dnsrch[0] = NULL;
return 0;
}
#endif
......@@ -381,7 +383,7 @@ __res_vinit(res_state statp, int preinit) {
/* Add the domain search list */
havesearch = load_domain_search_list(statp);
#else /* IGNORE resolv.conf */
#else /* !ANDROID_CHANGES - IGNORE resolv.conf in Android */
#define MATCH(line, name) \
(!strncmp(line, name, sizeof(name) - 1) && \
(line[sizeof(name) - 1] == ' ' || \
......@@ -534,7 +536,7 @@ __res_vinit(res_state statp, int preinit) {
statp->nsort = nsort;
(void) fclose(fp);
}
#endif /* ANDROID_CHANGES */
#endif /* !ANDROID_CHANGES */
/*
* Last chance to get a nameserver. This should not normally
* be necessary
......
......@@ -566,4 +566,12 @@ __END_DECLS
#include "arpa_nameser_compat.h"
#endif
#if 0
# include <logd.h>
# define XLOG(...) \
__libc_android_log_print(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__)
#else
#define XLOG(...) do {} while (0)
#endif
#endif /* !_ARPA_NAMESER_H_ */
......@@ -41,11 +41,11 @@ int gethostname(char* buff, size_t buflen)
int namelen = strlen(name.nodename);
if ((int)buflen < namelen+1) {
errno = EINVAL;
errno = EINVAL;
result = -1;
} else {
memcpy( buff, name.nodename, namelen+1 );
}
}
}
return result;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment