about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2017-07-14 21:46:42 -0400
committerFlorian Weimer <fweimer@redhat.com>2017-10-07 13:30:33 +0200
commit0279dcae8825f5835d636a68372f6b4e72eb27f3 (patch)
tree5fb8d520536fbf13325d648835620578a9c7b5e4
parentac93084c086ff06f815c405c9eb36a2b1f02da6a (diff)
downloadglibc-0279dcae8825f5835d636a68372f6b4e72eb27f3.tar.gz
glibc-0279dcae8825f5835d636a68372f6b4e72eb27f3.tar.xz
glibc-0279dcae8825f5835d636a68372f6b4e72eb27f3.zip
Fix BZ #21654 - grp-merge.c alignment
* grp/grp_merge.c (__copy_grp): Align char** to minimum pointer
alignment not char alignment.
(__merge_grp): Likewise.

(cherry picked from commit 4fa8ae49aa169fb8d97882938e8bee3ed9ce5410)
-rw-r--r--ChangeLog7
-rw-r--r--grp/grp-merge.c16
2 files changed, 23 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 53e80f848a..f4e2c5d3eb 100644
--- 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-22  Joseph Myers  <joseph@codesourcery.com>
 
 	[BZ #21987]
diff --git a/grp/grp-merge.c b/grp/grp-merge.c
index 77c494d159..6590e5d823 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)) != 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];