This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Adjust pointers to triplets in netgroup query data (BZ #16474)
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 21 Jan 2014 22:54:51 +0530
- Subject: [PATCH] Adjust pointers to triplets in netgroup query data (BZ #16474)
- Authentication-results: sourceware.org; auth=none
Hi,
Here's yet another netgroup fix.
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.
Tested on Fedora rawhide (x86_64). OK to commit?
Siddhesh
[BZ #16474]
* nscd/netgroupcache.c (addgetnetgrentX): Adjust triplet
string pointers after reallocation.
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index 58234b1..d5521e2 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,