about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@redhat.com>2011-09-26 17:49:14 +0200
committerAndreas Schwab <schwab@redhat.com>2011-10-07 11:46:18 +0200
commit2ae6256336c3604b245094ef6e07ca52414b8a7e (patch)
treed82084daf1dc418f6412e0c770d463182253a568
parent8bd683657e8ab1e6e0e787d6c00e763d8393f5e5 (diff)
downloadglibc-2ae6256336c3604b245094ef6e07ca52414b8a7e.tar.gz
glibc-2ae6256336c3604b245094ef6e07ca52414b8a7e.tar.xz
glibc-2ae6256336c3604b245094ef6e07ca52414b8a7e.zip
Correctly reparse group line after enlarging the buffer
(cherry picked from commit 32c76b63be605d12314e0c6ac2bd702c883d1423)
-rw-r--r--ChangeLog5
-rw-r--r--nss/nss_files/files-initgroups.c12
2 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 1ee1880716..4b46b64cbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c
index 113abf2821..c343b35e56 100644
--- a/nss/nss_files/files-initgroups.c
+++ b/nss/nss_files/files-initgroups.c
@@ -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)
 	{
@@ -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))
@@ -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)