From: Pavel Šimerda Date: Thu, 9 Oct 2014 16:20:22 +0000 (+0200) Subject: backends: pass only initialized data to nsswitch gethostbyname4_r X-Git-Url: https://www.sourceware.org/git/?a=commitdiff_plain;h=c78b0665645ad18cc026373cf13404c0ddb64bf8;p=netresolve.git backends: pass only initialized data to nsswitch gethostbyname4_r 1) Initualize the result pointer to NULL before passing a pointer to it This avoids memory corruption caused by _nss_files_gethostbyname4_r which for some unknown reason attempts to use the random memory referenced from the pointer that is supposed to be the output parameter. 2) Initialize the TTL value before passing a pointer to it I'm not yet sure what is the correct behavior regarding TTL in the nsswitch interface. It seems that nscd/aicache.c in glibc source code uses INT32_MAX and expects the module to clamp it down if possible. But that belongs to a different commit. --- diff --git a/backends/nss.c b/backends/nss.c index d2c8a8f..638834f 100644 --- a/backends/nss.c +++ b/backends/nss.c @@ -207,9 +207,13 @@ start(netresolve_query_t query, char **settings) } else if (node && priv.gethostbyname4_r && family == AF_UNSPEC) { char buffer[SIZE] = { 0 }; enum nss_status status; - struct gaih_addrtuple *result; + /* The libnss_files.so plugin checks the gaih_addrtuple pointer for being + * NULL and fails badly otherwise. Whether such behavior is correct + * remains a question. + */ + struct gaih_addrtuple *result = NULL; int errnop, h_errnop; - int32_t ttl; + int32_t ttl = 0; /* Without this, libnss_files won't resolve using multiple records * in /etc/hosts, e.g. won't return both IPv4 and IPv6 for "localhost"