HomeFreeBSD

libc/nss: Restore iterator state when doing passwd/group lookups

Description

libc/nss: Restore iterator state when doing passwd/group lookups

The getpwent(3) and getgrent(3) implementations maintain some internal
iterator state. Interleaved calls to functions which do passwd/group
lookups using a key, such as getpwnam(3), would in some cases clobber
this state, causing a subsequent getpwent() or getgrent() call to
restart iteration from the beginning of the database or to terminate
early. This is particularly troublesome in programming environments
where execution of green threads is interleaved within a single OS
thread.

Take care to restore any iterator state following a keyed lookup. The
"files" provider for the passwd database was already handling this
correctly, but "compat" was not, and both providers had this problem
when accessing the group database.

PR: 252094
Submitted by: Viktor Dukhovni <ietf-dane@dukhovni.org>
MFC after: 1 month

Details

Provenance
markjAuthored on Jan 21 2021, 7:30 PM
Parents
rG7abc10098b3d: libc/nss tests: Fix getpw and getgr single-pass tests
Branches
Unknown
Tags
Unknown