]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix BZ #21654 - grp-merge.c alignment
authorDJ Delorie <dj@delorie.com>
Sat, 15 Jul 2017 01:46:42 +0000 (21:46 -0400)
committerFlorian Weimer <fweimer@redhat.com>
Sat, 7 Oct 2017 11:30:00 +0000 (13:30 +0200)
* grp/grp_merge.c (__copy_grp): Align char** to minimum pointer
alignment not char alignment.
(__merge_grp): Likewise.

(cherry picked from commit 4fa8ae49aa169fb8d97882938e8bee3ed9ce5410)

ChangeLog
grp/grp-merge.c

index ecc0da0b02a461e73b8a9afcd13842f8e082db04..fe5103f03e6b6316cb5c60557033259e0875e799 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-07-14  DJ Delorie  <dj@redhat.com>
+
+       [BZ #21654]
+       * grp/grp_merge.c (__copy_grp): Align char** to minimum pointer
+       alignment not char alignment.
+       (__merge_grp): Likewise.
+
 2017-08-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        [BZ #21871]
index 0a1eb38d2c96bf7ad8f82c5668ac035512506b6a..50573b898627f55652831eb4602ab468c9323868 100644 (file)
@@ -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)) != 0)
+    {
+      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)) != 0)
+    {
+      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];