public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] BZ#19741: Fix possible assertion failure calling gethostbyname on m68k
@ 2017-07-11 20:12 James Clarke
  0 siblings, 0 replies; only message in thread
From: James Clarke @ 2017-07-11 20:12 UTC (permalink / raw)
  To: libc-alpha; +Cc: James Clarke, John Paul Adrian Glaubitz

On m68k, pointers are only required to be 2-byte aligned, and this is
reflected in __alignof__ (char *) being 2. However, the assertion in
_nss_files_gethostbyname3_r asserts that the pointer is sizeof (char *)
aligned, which is not always true, as parse_list only ensures bufferend
is __alignof__ (char *) aligned. Therefore, weaken this assertion and
alter the rounding to use __alignof__ (char *) too rather than
over-aligning.

	[BZ #19741]
	* nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r):
	Only enforce and preserve __alignof__ (char *) alignment for
	bufferend, rather than sizeof (char *).

Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
---
 nss/nss_files/files-hosts.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index bccb6a5780..958c21b1b4 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -211,12 +211,12 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
 		    }

 		  /* Make sure bufferend is aligned.  */
-		  assert ((bufferend - (char *) 0) % sizeof (char *) == 0);
+		  assert ((bufferend - (char *) 0) % __alignof__ (char *) == 0);

 		  /* Now we can check whether the buffer is large enough.
 		     16 is the maximal size of the IP address.  */
 		  if (bufferend + 16 + (naddrs + 2) * sizeof (char *)
-		      + roundup (newstrlen, sizeof (char *))
+		      + roundup (newstrlen, __alignof__ (char *))
 		      + (naliases + newaliases + 1) * sizeof (char *)
 		      >= buffer + buflen)
 		    {
@@ -228,7 +228,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,

 		  new_h_addr_list =
 		    (char **) (bufferend
-			       + roundup (newstrlen, sizeof (char *))
+			       + roundup (newstrlen, __alignof__ (char *))
 			       + 16);
 		  new_h_aliases =
 		    (char **) ((char *) new_h_addr_list
@@ -263,9 +263,10 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
 		  new_h_aliases[naliases] = NULL;

 		  /* Round up the buffer end address.  */
-		  bufferend += (sizeof (char *)
+		  bufferend += (__alignof__ (char *)
 				- ((bufferend - (char *) 0)
-				   % sizeof (char *))) % sizeof (char *);
+				   % __alignof__ (char *)))
+			       % __alignof__ (char *);

 		  /* Now the new address.  */
 		  new_h_addr_list[naddrs++] =
--
2.13.2

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-11 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-11 20:12 [PATCH] BZ#19741: Fix possible assertion failure calling gethostbyname on m68k James Clarke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).