Message ID | ed949aea12891b6ef43f57f17080871a4e99203d.1594974444.git.fweimer@redhat.com |
---|---|
State | New |
Headers | show |
Series | Fix fgetsgent_r data corruption bug (20338) | expand |
On 7/17/20 4:30 AM, Florian Weimer via Libc-alpha wrote: OK for 2.32 Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com> > --- > pwd/fgetpwent_r.c | 43 ++++++------------------------------------- > 1 file changed, 6 insertions(+), 37 deletions(-) > > diff --git a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c > index 26b0ee52aa..0a2e4a55e2 100644 > --- a/pwd/fgetpwent_r.c > +++ b/pwd/fgetpwent_r.c > @@ -20,9 +20,6 @@ > #include <stdio.h> > #include <pwd.h> > > -#define flockfile(s) _IO_flockfile (s) > -#define funlockfile(s) _IO_funlockfile (s) > - > /* Define a line parsing function using the common code > used in the nss_files module. */ > > @@ -72,39 +69,11 @@ int > __fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer, > size_t buflen, struct passwd **result) > { > - char *p; > - > - flockfile (stream); > - do > - { > - buffer[buflen - 1] = '\xff'; > - p = fgets_unlocked (buffer, buflen, stream); > - if (p == NULL && feof_unlocked (stream)) > - { > - funlockfile (stream); > - *result = NULL; > - __set_errno (ENOENT); > - return errno; > - } > - if (p == NULL || buffer[buflen - 1] != '\xff') > - { > - funlockfile (stream); > - *result = NULL; > - __set_errno (ERANGE); > - return errno; > - } > - > - /* Skip leading blanks. */ > - while (isspace (*p)) > - ++p; > - } while (*p == '\0' || *p == '#' /* Ignore empty and comment lines. */ > - /* Parse the line. If it is invalid, loop to > - get the next line of the file to parse. */ > - || ! parse_line (p, resbuf, (void *) buffer, buflen, &errno)); > - > - funlockfile (stream); > - > - *result = resbuf; > - return 0; > + int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line); > + if (ret == 0) > + *result = resbuf; > + else > + *result = NULL; > + return ret; > } > weak_alias (__fgetpwent_r, fgetpwent_r) >
diff --git a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c index 26b0ee52aa..0a2e4a55e2 100644 --- a/pwd/fgetpwent_r.c +++ b/pwd/fgetpwent_r.c @@ -20,9 +20,6 @@ #include <stdio.h> #include <pwd.h> -#define flockfile(s) _IO_flockfile (s) -#define funlockfile(s) _IO_funlockfile (s) - /* Define a line parsing function using the common code used in the nss_files module. */ @@ -72,39 +69,11 @@ int __fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer, size_t buflen, struct passwd **result) { - char *p; - - flockfile (stream); - do - { - buffer[buflen - 1] = '\xff'; - p = fgets_unlocked (buffer, buflen, stream); - if (p == NULL && feof_unlocked (stream)) - { - funlockfile (stream); - *result = NULL; - __set_errno (ENOENT); - return errno; - } - if (p == NULL || buffer[buflen - 1] != '\xff') - { - funlockfile (stream); - *result = NULL; - __set_errno (ERANGE); - return errno; - } - - /* Skip leading blanks. */ - while (isspace (*p)) - ++p; - } while (*p == '\0' || *p == '#' /* Ignore empty and comment lines. */ - /* Parse the line. If it is invalid, loop to - get the next line of the file to parse. */ - || ! parse_line (p, resbuf, (void *) buffer, buflen, &errno)); - - funlockfile (stream); - - *result = resbuf; - return 0; + int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line); + if (ret == 0) + *result = resbuf; + else + *result = NULL; + return ret; } weak_alias (__fgetpwent_r, fgetpwent_r)