00db10
commit 31d0a4fa646db8b8c97ce24e0ec0a7b73de4fca1
00db10
Author: Florian Weimer <fweimer@redhat.com>
00db10
Date:   Sat Jun 11 12:12:56 2016 +0200
00db10
00db10
    nss_db: Fix initialization of iteration position [BZ #20237]
00db10
    
00db10
    When get*ent is called without a preceding set*ent, we need
00db10
    to set the initial iteration position in get*ent.
00db10
    
00db10
    Reproducer: Add “services: db files” to /etc/nsswitch.conf, then run
00db10
    “perl -e getservent”.  It will segfault before this change, and exit
00db10
    silently after it.
00db10
00db10
Index: b/nss/nss_db/db-XXX.c
00db10
===================================================================
00db10
--- a/nss/nss_db/db-XXX.c
00db10
+++ b/nss/nss_db/db-XXX.c
00db10
@@ -76,7 +76,7 @@ CONCAT(_nss_db_set,ENTNAME) (int stayope
00db10
       keep_db |= stayopen;
00db10
 
00db10
       /* Reset the sequential index.  */
00db10
-      entidx  = (const char *) state.header + state.header->valstroffset;
00db10
+      entidx  = NULL;
00db10
     }
00db10
 
00db10
   __libc_lock_unlock (lock);
00db10
@@ -249,8 +249,14 @@ CONCAT(_nss_db_get,ENTNAME_r) (struct ST
00db10
 	  H_ERRNO_SET (NETDB_INTERNAL);
00db10
 	  goto out;
00db10
 	}
00db10
+      entidx = NULL;
00db10
     }
00db10
 
00db10
+  /* Start from the beginning if freshly initialized or reset
00db10
+     requested by set*ent.  */
00db10
+  if (entidx == NULL)
00db10
+    entidx = (const char *) state.header + state.header->valstroffset;
00db10
+
00db10
   status = NSS_STATUS_UNAVAIL;
00db10
   if (state.header != MAP_FAILED)
00db10
     {