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: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 24 Jan 2014 14:27:57 +0530
- 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> <20140123123841 dot GA5631 at domone dot podge>
On Thu, Jan 23, 2014 at 01:38:41PM +0100, OndÅej BÃlka wrote:
> 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.
I had made an untested change (dropped brackets around n* - buffer)
before posting it and I found out now that it did not compile. This
is what I've pushed finally, which is essentially the same change with
brackets back in place.
Siddhesh
commit 5d41dadf31bc8a2f9c34c40d52a442d3794e405c
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Fri Jan 24 13:51:15 2014 +0530
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.
diff --git a/ChangeLog b/ChangeLog
index 0f4453e..1d19695 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-01-24 Siddhesh Poyarekar <siddhesh@redhat.com>
+
+ [BZ #16474]
+ * nscd/netgroupcache.c (addgetnetgrentX): Adjust triplet
+ string pointers after reallocation.
+
2014-01-24 Kaz Kojima <kkojima@rr.iij4u.or.jp>
* sysdeps/unix/sysv/linux/sh/sys/ucontext.h: Use __SH4__ and
diff --git a/NEWS b/NEWS
index f4f22a8..5601403 100644
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,7 @@ Version 2.19
16151, 16153, 16167, 16169, 16172, 16195, 16214, 16245, 16271, 16274,
16283, 16289, 16293, 16314, 16316, 16330, 16337, 16338, 16356, 16365,
16366, 16369, 16372, 16375, 16379, 16384, 16385, 16386, 16387, 16390,
- 16394, 16400, 16407, 16408, 16414, 16430, 16431, 16453.
+ 16394, 16400, 16407, 16408, 16414, 16430, 16431, 16453, 16474.
* Slovenian translations for glibc messages have been contributed by the
Translation Project's Slovenian team of translators.
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index 58234b1..924567c 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,