From patchwork Thu May 20 09:42:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 53054 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id F31A9B7D76 for ; Thu, 20 May 2010 19:43:07 +1000 (EST) Received: by ozlabs.org (Postfix) id 245C3B7D30; Thu, 20 May 2010 19:43:01 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by ozlabs.org (Postfix) with ESMTP id AE9D9B7D2E for ; Thu, 20 May 2010 19:43:00 +1000 (EST) Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4K9grJT010647 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 20 May 2010 05:42:53 -0400 Received: from warthog.cambridge.redhat.com (kibblesnbits.boston.devel.redhat.com [10.16.60.12]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4K9gnl7014705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 20 May 2010 05:42:52 -0400 Received: from [127.0.0.1] (helo=warthog.procyon.org.uk) by warthog.cambridge.redhat.com with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1OF2HA-0007x4-OX; Thu, 20 May 2010 10:42:48 +0100 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells Subject: [PATCH] PPC: Fix zero length strncmp() on powerpc To: srostedt@redhat.com Date: Thu, 20 May 2010 10:42:48 +0100 Message-ID: <20100520094248.30540.89543.stgit@warthog.procyon.org.uk> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Cc: linuxppc-dev@ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org When strncmp() on powerpc is given a length of zero, it detects this and returns early to make the comparison loop simpler. When it does this, however, it fails to set a return value, and thus returns the address of the first string as the number of the character match. It should return 0 instead in this case. This can be tested by compiling and attempting to load the following module: #include #include char string1[1], string2[1]; size_t count_global = 0; static int __init strncmp_init(void) { string1[0] = string2[0] = 0; if (strncmp(string1, string2, count_global)) { printk("Strncmp Bug!\n"); return -EIO; } return -ENOANO; } module_init(strncmp_init); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Probe strncmp() bug"); It should return error "No anode" on success and "I/O error" on failure. The module will not be retained. Signed-off-by: David Howells --- arch/powerpc/lib/string.S | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/lib/string.S b/arch/powerpc/lib/string.S index 64e2e49..46fe390 100644 --- a/arch/powerpc/lib/string.S +++ b/arch/powerpc/lib/string.S @@ -71,7 +71,7 @@ _GLOBAL(strcmp) _GLOBAL(strncmp) PPC_LCMPI r5,0 - beqlr + beq- 2f mtctr r5 addi r5,r3,-1 addi r4,r4,-1 @@ -82,6 +82,8 @@ _GLOBAL(strncmp) beqlr 1 bdnzt eq,1b blr +2: li r3,0 + blr _GLOBAL(strlen) addi r4,r3,-1