nwrap: Fix segfaults while reloading hosts file
authorAndreas Schneider <asn@samba.org>
Thu, 17 Dec 2015 07:46:33 +0000 (08:46 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 11 Jan 2016 11:25:32 +0000 (12:25 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/nss_wrapper/nss_wrapper.c

index f48b9cc7e8d65d1f992a014d8dad80fc2ed833a8..c4f1b33e4965250d8d83786a17929f2403d15dd2 100644 (file)
@@ -2890,6 +2890,7 @@ static void nwrap_he_unload(struct nwrap_cache *nwrap)
        struct nwrap_entdata *ed;
        struct nwrap_entlist *el;
        size_t i;
+       int rc;
 
        nwrap_vector_foreach (ed, nwrap_he->entries, i)
        {
@@ -2915,6 +2916,18 @@ static void nwrap_he_unload(struct nwrap_cache *nwrap)
 
        nwrap_he->num = 0;
        nwrap_he->idx = 0;
+
+       /*
+        * If we unload the file, the pointers in the hash table point to
+        * invalid memory. So we need to destroy the hash table and recreate
+        * it.
+        */
+       hdestroy();
+       rc = hcreate(max_hostents);
+       if (rc == 0) {
+               NWRAP_LOG(NWRAP_LOG_ERROR, "Failed to initialize hash table");
+               exit(-1);
+       }
 }