Skip to contentSkip to conversation

Bug in boot code memcmp with zero length

PATCH Mike Ditto 1 participant 1 message Oct 17, 2008

lore
Share & tools
lore

Mike Ditto

author
#0 lore raw

I noticed, when trying to use, e.g.,
node = find_node_by_prop_value(prev, "booleanprop", "", 0)) to search for all nodes with a certain boolean property, that memcmp() returns garbage when comparing zero bytes. It should return zero.

Index: arch/powerpc/boot/string.S
===================================================================
retrieving revision 1.1.1.1

powerpc/boot/string.S +3 -1
diff -u -r1.1.1.1 string.S
@@ -235,7 +235,7 @@
 	.globl	memcmp
 memcmp:
 	cmpwi	0,r5,0
-	blelr
+	ble	2f
 	mtctr	r5
 	addi	r6,r3,-1
 	addi	r4,r4,-1
@@ -243,6 +243,8 @@
 	lbzu	r0,1(r4)
 	subf.	r3,r0,r3
 	bdnzt	2,1b
+	blr
+2:	li	r3,0
 	blr