backends: pass only initialized data to nsswitch gethostbyname4_r
authorPavel Šimerda <psimerda@redhat.com>
Thu, 9 Oct 2014 16:20:22 +0000 (18:20 +0200)
committerPavel Šimerda <psimerda@redhat.com>
Thu, 9 Oct 2014 16:51:37 +0000 (18:51 +0200)
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.

backends/nss.c

index d2c8a8f73e0941e7b1f06dc8727fc7b9e07f01c9..638834f2391294681841206b16210702fe37d1d0 100644 (file)
@@ -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"
This page took 0.059456 seconds and 5 git commands to generate.