diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-05-19 14:09:38 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-05-19 14:09:57 +0200 |
commit | 790b8dda4455865cb8c3a47801f4304c1a43baf6 (patch) | |
tree | f410f4425e93ec71223199ef2075574758bb1541 /nss/nss_compat/compat-pwd.c | |
parent | 765de945efc5d5602999b2999fe8abdf04881370 (diff) | |
download | glibc-790b8dda4455865cb8c3a47801f4304c1a43baf6.tar glibc-790b8dda4455865cb8c3a47801f4304c1a43baf6.tar.gz glibc-790b8dda4455865cb8c3a47801f4304c1a43baf6.tar.bz2 glibc-790b8dda4455865cb8c3a47801f4304c1a43baf6.zip |
nss_compat: internal_end*ent may clobber errno, hiding ERANGE [BZ #25976]
During cleanup, before returning from get*_r functions, the end*ent
calls must not change errno. Otherwise, an ERANGE error from the
underlying implementation can be hidden, causing unexpected lookup
failures. This commit introduces an internal_end*ent_noerror
function which saves and restore errno, and marks the original
internal_end*ent function as warn_unused_result, so that it is used
only in contexts were errors from it can be handled explicitly.
Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'nss/nss_compat/compat-pwd.c')
-rw-r--r-- | nss/nss_compat/compat-pwd.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/nss/nss_compat/compat-pwd.c b/nss/nss_compat/compat-pwd.c index dfb454f777..394e39b811 100644 --- a/nss/nss_compat/compat-pwd.c +++ b/nss/nss_compat/compat-pwd.c @@ -261,7 +261,7 @@ _nss_compat_setpwent (int stayopen) } -static enum nss_status +static enum nss_status __attribute_warn_unused_result__ internal_endpwent (ent_t *ent) { if (ent->stream != NULL) @@ -289,6 +289,15 @@ internal_endpwent (ent_t *ent) return NSS_STATUS_SUCCESS; } +/* Like internal_endpwent, but preserve errno in all cases. */ +static void +internal_endpwent_noerror (ent_t *ent) +{ + int saved_errno = errno; + enum nss_status unused __attribute__ ((unused)) = internal_endpwent (ent); + __set_errno (saved_errno); +} + enum nss_status _nss_compat_endpwent (void) { @@ -824,7 +833,7 @@ _nss_compat_getpwnam_r (const char *name, struct passwd *pwd, if (result == NSS_STATUS_SUCCESS) result = internal_getpwnam_r (name, pwd, &ent, buffer, buflen, errnop); - internal_endpwent (&ent); + internal_endpwent_noerror (&ent); return result; } @@ -1063,7 +1072,7 @@ _nss_compat_getpwuid_r (uid_t uid, struct passwd *pwd, if (result == NSS_STATUS_SUCCESS) result = internal_getpwuid_r (uid, pwd, &ent, buffer, buflen, errnop); - internal_endpwent (&ent); + internal_endpwent_noerror (&ent); return result; } |