9832fd
commit 99135114ba23c3110b7e4e650fabdc5e639746b7
9832fd
Author: DJ Delorie <dj@redhat.com>
9832fd
Date:   Fri Jun 28 18:30:00 2019 -0500
9832fd
9832fd
    nss_db: fix endent wrt NULL mappings [BZ #24695] [BZ #24696]
9832fd
    
9832fd
    nss_db allows for getpwent et al to be called without a set*ent,
9832fd
    but it only works once.  After the last get*ent a set*ent is
9832fd
    required to restart, because the end*ent did not properly reset
9832fd
    the module.  Resetting it to NULL allows for a proper restart.
9832fd
    
9832fd
    If the database doesn't exist, however, end*ent erroniously called
9832fd
    munmap which set errno.
9832fd
9832fd
Note: the test case has not been included in this backport as the
9832fd
required test harness infrastructure does not exist.
9832fd
    
9832fd
diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c
9832fd
index 8a83d6b..3fa11e9 100644
9832fd
--- a/nss/nss_db/db-open.c
9832fd
+++ b/nss/nss_db/db-open.c
9832fd
@@ -63,5 +63,9 @@ internal_setent (const char *file, struct nss_db_map *mapping)
9832fd
 void
9832fd
 internal_endent (struct nss_db_map *mapping)
9832fd
 {
9832fd
-  munmap (mapping->header, mapping->len);
9832fd
+  if (mapping->header != NULL)
9832fd
+    {
9832fd
+      munmap (mapping->header, mapping->len);
9832fd
+      mapping->header = NULL;
9832fd
+    }
9832fd
 }