From 31d0a4fa646db8b8c97ce24e0ec0a7b73de4fca1 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Sat, 11 Jun 2016 12:12:56 +0200 Subject: nss_db: Fix initialization of iteration position [BZ #20237] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- nss/nss_db/db-XXX.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'nss') diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c index 125a5e9b12..2d13edda27 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) { -- cgit v1.2.3