From: David Howells <dhowells@redhat.com>
To: srostedt@redhat.com
Cc: linuxppc-dev@ozlabs.org
Subject: [PATCH] PPC: Fix zero length strncmp() on powerpc
Date: Thu, 20 May 2010 10:42:48 +0100 [thread overview]
Message-ID: <20100520094248.30540.89543.stgit@warthog.procyon.org.uk> (raw)
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 <linux/init.h>
#include <linux/module.h>
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 <dhowells@redhat.com>
---
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
reply other threads:[~2010-05-20 9:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100520094248.30540.89543.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox