aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-06-11 12:12:56 +0200
committerMike Frysinger <vapier@gentoo.org>2016-11-12 00:44:38 -0500
commit1ad4b4277f6f9c9c1d124357ab19d26dee61eb80 (patch)
tree173d4941b527458649f399949d1f3bf2061f71da
parentf7076e089854bbbce413dd9a832d3f39515d0d45 (diff)
downloadglibc-1ad4b4277f6f9c9c1d124357ab19d26dee61eb80.zip
glibc-1ad4b4277f6f9c9c1d124357ab19d26dee61eb80.tar.gz
glibc-1ad4b4277f6f9c9c1d124357ab19d26dee61eb80.tar.bz2
nss_db: Fix initialization of iteration position [BZ #20237]
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) (cherry picked from commit 79ad3fa2b1f38997be255d4eb709da928b66796a)
-rw-r--r--nss/nss_db/db-XXX.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c
index 125a5e9..2d13edd 100644
--- a/nss/nss_db/db-XXX.c
+++ b/nss/nss_db/db-XXX.c
@@ -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)
{