about summary refs log tree commit diff
path: root/nscd/netgroupcache.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2014-01-24 13:51:15 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2014-01-24 13:51:15 +0530
commit5d41dadf31bc8a2f9c34c40d52a442d3794e405c (patch)
tree1033a8751da91bf20f3f870374fb15fe76aa797b /nscd/netgroupcache.c
parent0bad441c77fa4ff382dd3990542dcf52052b2121 (diff)
downloadglibc-5d41dadf31bc8a2f9c34c40d52a442d3794e405c.tar.gz
glibc-5d41dadf31bc8a2f9c34c40d52a442d3794e405c.tar.xz
glibc-5d41dadf31bc8a2f9c34c40d52a442d3794e405c.zip
Adjust pointers to triplets in netgroup query data (BZ #16474)
The _nss_*_getnetgrent_r query populates the netgroup results in the
allocated buffer and then sets the result triplet to point to strings
in the buffer.  This is a problem when the buffer is reallocated since
the pointers to the triplet strings are no longer valid.  The pointers
need to be adjusted so that they now point to strings in the
reallocated buffer.
Diffstat (limited to 'nscd/netgroupcache.c')
-rw-r--r--nscd/netgroupcache.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index 58234b1492..924567c3f3 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -241,7 +241,17 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
 				if (buflen - req->key_len - bufused < needed)
 				  {
 				    buflen += MAX (buflen, 2 * needed);
-				    buffer = xrealloc (buffer, buflen);
+				    char *newbuf = xrealloc (buffer, buflen);
+				    /* Adjust the pointers in the new
+				       buffer.  */
+				    nhost = (nhost ? newbuf + (nhost - buffer)
+					     : NULL);
+				    nuser = (nuser ? newbuf + (nuser - buffer)
+					     : NULL);
+				    ndomain = (ndomain
+					       ? newbuf + (ndomain - buffer)
+					       : NULL);
+				    buffer = newbuf;
 				  }
 
 				nhost = memcpy (buffer + bufused,