This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Adjust pointers to triplets in netgroup query data (BZ #16474)
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 23 Jan 2014 13:38:41 +0100
- Subject: Re: [PATCH] Adjust pointers to triplets in netgroup query data (BZ #16474)
- Authentication-results: sourceware.org; auth=none
- References: <20140121172451 dot GJ5544 at spoyarek dot pnq dot redhat dot com>
On Tue, Jan 21, 2014 at 10:54:51PM +0530, Siddhesh Poyarekar wrote:
> 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?
>
Looks ok.
> 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,
--
Just type 'mv * /dev/null'.