Skip to content

Commit

Permalink
Correctly reparse group line after enlarging the buffer
Browse files Browse the repository at this point in the history
(cherry picked from commit 32c76b6)
  • Loading branch information
Andreas Schwab committed Oct 7, 2011
1 parent 8bd6836 commit 2ae6256
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2011-09-27 Andreas Schwab <schwab@redhat.com>

* nss/nss_files/files-initgroups.c (_nss_files_initgroups_dyn):
Reread the line before reparsing it.

2011-08-29 Jiri Olsa <jolsa@redhat.com>

* sysdeps/i386/dl-trampoline.S (_dl_runtime_profile): Fix cfi
Expand Down
12 changes: 8 additions & 4 deletions nss/nss_files/files-initgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start,
gid_t *groups = *groupsp;

/* We have to iterate over the entire file. */
while (!feof_unlocked (stream))
while (1)
{
fpos_t pos;
fgetpos (stream, &pos);
ssize_t n = getline (&line, &linelen, stream);
if (n < 0)
{
Expand All @@ -64,9 +66,8 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start,
}

struct group grp;
int res;
while ((res = _nss_files_parse_grent (line, &grp, buffer, buflen,
errnop)) == -1)
int res = _nss_files_parse_grent (line, &grp, buffer, buflen, errnop);
if (res == -1)
{
size_t newbuflen = 2 * buflen;
if (buffer_use_malloc || ! __libc_use_alloca (buflen + newbuflen))
Expand All @@ -85,6 +86,9 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start,
}
else
buffer = extend_alloca (buffer, buflen, newbuflen);
/* Reread current line, the parser has clobbered it. */
fsetpos (stream, &pos);
continue;
}

if (res > 0 && grp.gr_gid != group)
Expand Down

0 comments on commit 2ae6256

Please sign in to comment.