mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-08 18:30:18 +00:00
Avoid undefined behaviour in netgroupcache
Using a buffer after it has been reallocated is undefined behaviour, so get offsets of the triplets in the old buffer before reallocating it.
This commit is contained in:
parent
0c00f062dd
commit
af37a8a349
@ -1,3 +1,8 @@
|
|||||||
|
2014-01-27 Siddhesh Poyarekar <siddhesh@redhat.com>
|
||||||
|
|
||||||
|
* nscd/netgroupcache.c (addgetnetgrentX): Compute offset from
|
||||||
|
the old buffer before realloc.
|
||||||
|
|
||||||
2014-01-27 Allan McRae <allan@archlinux.org>
|
2014-01-27 Allan McRae <allan@archlinux.org>
|
||||||
|
|
||||||
* po/fr.po: Update French translation from translation project.
|
* po/fr.po: Update French translation from translation project.
|
||||||
|
@ -241,15 +241,21 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
|
|||||||
if (buflen - req->key_len - bufused < needed)
|
if (buflen - req->key_len - bufused < needed)
|
||||||
{
|
{
|
||||||
buflen += MAX (buflen, 2 * needed);
|
buflen += MAX (buflen, 2 * needed);
|
||||||
|
/* Save offset in the old buffer. We don't
|
||||||
|
bother with the NULL check here since
|
||||||
|
we'll do that later anyway. */
|
||||||
|
size_t nhostdiff = nhost - buffer;
|
||||||
|
size_t nuserdiff = nuser - buffer;
|
||||||
|
size_t ndomaindiff = ndomain - buffer;
|
||||||
|
|
||||||
char *newbuf = xrealloc (buffer, buflen);
|
char *newbuf = xrealloc (buffer, buflen);
|
||||||
/* Adjust the pointers in the new
|
/* Fix up the triplet pointers into the new
|
||||||
buffer. */
|
buffer. */
|
||||||
nhost = (nhost ? newbuf + (nhost - buffer)
|
nhost = (nhost ? newbuf + nhostdiff
|
||||||
: NULL);
|
: NULL);
|
||||||
nuser = (nuser ? newbuf + (nuser - buffer)
|
nuser = (nuser ? newbuf + nuserdiff
|
||||||
: NULL);
|
: NULL);
|
||||||
ndomain = (ndomain
|
ndomain = (ndomain ? newbuf + ndomaindiff
|
||||||
? newbuf + (ndomain - buffer)
|
|
||||||
: NULL);
|
: NULL);
|
||||||
buffer = newbuf;
|
buffer = newbuf;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user