BZ#19741: Fix possible assertion failure calling gethostbyname on m68k

Message ID 20170711201222.83720-1-jrtc27@jrtc27.com
State New, archived
Headers

Commit Message

Jessica Clarke July 11, 2017, 8:12 p.m. UTC
  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(-)

--
2.13.2
  

Patch

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++] =