mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
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.
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user