From patchwork Tue Jul 11 20:12:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jessica Clarke X-Patchwork-Id: 21547 Received: (qmail 58939 invoked by alias); 11 Jul 2017 20:12:49 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 58916 invoked by uid 89); 11 Jul 2017 20:12:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:501, H*Ad:D*fu-berlin.de, weaken X-HELO: mail-wr0-f176.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=E8R1XnUDWSV3yeK60zIzPDYrau7rObdI6Nv08Fp7shE=; b=cHRjI1Uv4olAxp0wM0yP8R4yIfXVVZpvJOqsyotr0BW1UX6xyeklGmBfy5+ZF8N4/9 +++7c8NfetucVERGO4I1Bk3LFnOm+RCn1Mq7xKQBbbF3uEo6bp/s9SZ5QfzM6X+13h8a PpSuQW3sukFIAsXT3NmqWEyJJmA52BxhIwjX0xJNgg2QrIZihxDSAYJsDdIcJdqw+OA8 gU2cZ3M5gqHR62ghP0JHTk9jkN+tLslPgkNputDPbysQrkcQDXve9AV1RC0O1WvSjEf3 4T5+XKWkIW87W0cc0suGJo/lYFBaeSEuPIuaU20rSKc1f6qP2ppoop9IIwVmznUvlBth ku6w== X-Gm-Message-State: AIVw112LMYT6BTZDNyzfg34pa/LX3/LlEMWnPvVG1zCUrrJ68DvYnlet +qDj2hZ6RzPPnA4T4kyBrQ== X-Received: by 10.28.105.28 with SMTP id e28mr54359wmc.42.1499803964154; Tue, 11 Jul 2017 13:12:44 -0700 (PDT) From: James Clarke To: libc-alpha@sourceware.org Cc: James Clarke , John Paul Adrian Glaubitz Subject: [PATCH] BZ#19741: Fix possible assertion failure calling gethostbyname on m68k Date: Tue, 11 Jul 2017 21:12:22 +0100 Message-Id: <20170711201222.83720-1-jrtc27@jrtc27.com> 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 --- nss/nss_files/files-hosts.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.13.2 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++] =