1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-21 14:53:53 +03:00

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.
This commit is contained in:
Siddhesh Poyarekar
2014-01-24 13:51:15 +05:30
parent 0bad441c77
commit 5d41dadf31
3 changed files with 18 additions and 2 deletions

View File

@@ -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,