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.
} 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"