This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
grp/grp_merge.c alignment fix
- From: DJ Delorie <dj at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 13 Jul 2017 20:36:31 -0400
- Subject: grp/grp_merge.c alignment fix
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dj at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0757E7F3F1
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0757E7F3F1
Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=21654
I have a test for this in my nss_tests patch (posted separately),
which is a very large patch set (the individual test requires the new
framework) and thus I chose to keep it as a separate patch in case
this patch was accepted during the freeze and the testuite change was
deferred.
Tested on x86_64, where it fails the test I wrote before, and not
after, patching.
Note: I did not try to rewrite grp_merge.c using Florian's new
alloc_buffer code, as I felt that was inappropriate for this stage of
development (post-freeze).
[BZ #21654]
* grp/grp_merge.c (__copy_grp): Make sure pointers-to-not-char
are properly aligned.
(__merge_grp): Likewise.
diff --git a/grp/grp-merge.c b/grp/grp-merge.c
index 77c494d..d6a53cd 100644
--- a/grp/grp-merge.c
+++ b/grp/grp-merge.c
@@ -85,6 +85,14 @@ __copy_grp (const struct group srcgrp, const size_t buflen,
}
members[i] = NULL;
+ /* Align for pointers. We can't simply align C because we need to
+ align destbuf[c]. */
+ if (((uintptr_t)destbuf + c) & (__alignof__(char **) - 1))
+ {
+ uintptr_t mis_align = ((uintptr_t)destbuf + c) & (__alignof__(char **) - 1);
+ c += __alignof__(char **) - mis_align;
+ }
+
/* Copy the pointers from the members array into the buffer and assign them
to the gr_mem member of destgrp. */
destgrp->gr_mem = (char **) &destbuf[c];
@@ -168,6 +176,14 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
/* Add the NULL-terminator. */
members[savedmemcount + memcount] = NULL;
+ /* Align for pointers. We can't simply align C because we need to
+ align savedbuf[c]. */
+ if (((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1))
+ {
+ uintptr_t mis_align = ((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1);
+ c += __alignof__(char **) - mis_align;
+ }
+
/* Copy the member array back into the buffer after the member list and free
the member array. */
savedgrp->gr_mem = (char **) &savedbuf[c];