From patchwork Fri Sep 16 12:46:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierre Vittet X-Patchwork-Id: 114924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E408AB6F76 for ; Fri, 16 Sep 2011 22:47:29 +1000 (EST) Received: (qmail 26319 invoked by alias); 16 Sep 2011 12:47:28 -0000 Received: (qmail 26311 invoked by uid 22791); 16 Sep 2011 12:47:25 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from 4.mo4.mail-out.ovh.net (HELO mo4.mail-out.ovh.net) (178.32.98.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Sep 2011 12:47:06 +0000 Received: from mail177.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo4.mail-out.ovh.net (Postfix) with SMTP id 3EF331004C1C for ; Fri, 16 Sep 2011 14:47:31 +0200 (CEST) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 16 Sep 2011 14:47:04 +0200 Received: from unknown (HELO ?10.172.5.146?) (piervit@pvittet.com@193.52.208.229) by ns0.ovh.net with SMTP; 16 Sep 2011 14:47:01 +0200 Message-ID: <4E734541.7030204@pvittet.com> Date: Fri, 16 Sep 2011 14:46:57 +0200 From: Pierre Vittet User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org CC: Basile Starynkevitch , sje@cup.hp.com, Alexandre Lissy X-Ovh-Mailout: 178.32.228.4 (mo4.mail-out.ovh.net) Subject: [PATCH, libiberty] correct md5_process_bytes with unaligned pointers X-Ovh-Tracer-Id: 4991395762176065694 X-Ovh-Remote: 193.52.208.229 () X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeftddrfeeiucetggdotefuucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello, The patch is the result of the following threads: Here is a patch correcting md5_process_bytes when we are in the case of unaligned pointers.A pair of brace was missing, leading the buffer to be shift 2 times losing a part of its content. The patch also remove a preprocessor #if testing if _STRING_ARCH_unaligned is defined. This symbol is never defined in gcc and could be only used in CFLAGS. Looking at the code, it does not looks usefull to define it (and it is only tested on libiberty/md5.c and libiberty/sha1.c), as we already check the pointer alignement, so removing it clean the code. I searched on google, and it does not looks to be used. Does anyone want it or thing that it should not be removed? Ok for trunk ? Thanks! Pierre Vittet PS: I also write a small gcc plugin, allowing to easily test md5_process_bytes, if can change your environment in a way where the pointer buffer is not aligned, you should get the bug. 2011-09-16 Pierre Vittet * md5.c (md5_process_bytes): Remove unused _STRING_ARCH_unaligned, add missing braces. Index: libiberty/md5.c =================================================================== --- libiberty/md5.c (révision 178905) +++ libiberty/md5.c (copie de travail) @@ -227,7 +227,6 @@ md5_process_bytes (const void *buffer, size_t len, /* Process available complete blocks. */ if (len > 64) { -#if !_STRING_ARCH_unaligned /* To check alignment gcc has an appropriate operator. Other compilers don't. */ # if __GNUC__ >= 2 @@ -244,10 +243,11 @@ md5_process_bytes (const void *buffer, size_t len, len -= 64; } else -#endif - md5_process_block (buffer, len & ~63, ctx); - buffer = (const void *) ((const char *) buffer + (len & ~63)); - len &= 63; + { + md5_process_block (buffer, len & ~63, ctx); + buffer = (const void *) ((const char *) buffer + (len & ~63)); + len &= 63; + } } /* Move remaining bytes in internal buffer. */