]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nss_db: Fix initialization of iteration position [BZ #20237]
authorFlorian Weimer <fweimer@redhat.com>
Sat, 11 Jun 2016 10:12:56 +0000 (12:12 +0200)
committerRyan S. Arnold <ryan.arnold@linaro.org>
Sat, 22 Oct 2016 16:49:09 +0000 (11:49 -0500)
When get*ent is called without a preceding set*ent, we need
to set the initial iteration position in get*ent.

Reproducer: Add “services: db files” to /etc/nsswitch.conf, then run
“perl -e getservent”.  It will segfault before this change, and exit
silently after it.

(cherry picked from commit 31d0a4fa646db8b8c97ce24e0ec0a7b73de4fca1)

ChangeLog
nss/nss_db/db-XXX.c

index c2191da87e72811fd4e23fc7fd347e205ed6f971..7e37e6806c0753ada3452aa489355b9b30572763 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-06-11  Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #20237]
+       * nss/nss_db/db-XXX.c (set*ent): Reset entidx to NULL.
+       (get*ent): Set entidx to NULL during initialization.  If entidx is
+       NULL, start iteration from the beginning.
+
 2016-06-30  Andreas Schwab  <schwab@suse.de>
 
        [BZ #20262]
index 125a5e9b12616c345eaa14471d033a4ad307db96..2d13edda278cd9737542696352aeb2cfab0b34db 100644 (file)
@@ -77,7 +77,7 @@ CONCAT(_nss_db_set,ENTNAME) (int stayopen)
       keep_db |= stayopen;
 
       /* Reset the sequential index.  */
-      entidx  = (const char *) state.header + state.header->valstroffset;
+      entidx  = NULL;
     }
 
   __libc_lock_unlock (lock);
@@ -253,8 +253,14 @@ CONCAT(_nss_db_get,ENTNAME_r) (struct STRUCTURE *result, char *buffer,
          H_ERRNO_SET (NETDB_INTERNAL);
          goto out;
        }
+      entidx = NULL;
     }
 
+  /* Start from the beginning if freshly initialized or reset
+     requested by set*ent.  */
+  if (entidx == NULL)
+    entidx = (const char *) state.header + state.header->valstroffset;
+
   status = NSS_STATUS_UNAVAIL;
   if (state.header != MAP_FAILED)
     {