All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PPC: Fix zero length strncmp() on powerpc
@ 2010-05-20  9:42 David Howells
  0 siblings, 0 replies; only message in thread
From: David Howells @ 2010-05-20  9:42 UTC (permalink / raw
  To: srostedt; +Cc: linuxppc-dev

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-05-20  9:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-20  9:42 [PATCH] PPC: Fix zero length strncmp() on powerpc David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.