This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Adjust pointers to triplets in netgroup query data (BZ #16474)


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,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]