All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] strcmp: fix overflow error
@ 2009-11-17 16:51 Uwe Kleine-König
  2009-11-17 17:36 ` Andreas Schwab
  2009-11-17 17:41 ` Linus Torvalds
  0 siblings, 2 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2009-11-17 16:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: Michael Buesch, Peter Zijlstra, Andrew Morton, Linus Torvalds

strcmp("\x01", "\xef") returns 18 but it should return something < 0.
The reason is that the variable holding the result of the subtraction is
too small and overflows.

As strcmp is e.g. used to access data in squashfs this might result in
not finding files.

The same problem is fixed in strncmp.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Michael Buesch <mb@bu3sch.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
Hello,

I didn't hit this problem in the wild, only when checking for something
else.  Is this stable material anyhow?

Best regards
Uwe

 lib/string.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index b19b87a..661ff06 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -246,7 +246,7 @@ EXPORT_SYMBOL(strlcat);
 #undef strcmp
 int strcmp(const char *cs, const char *ct)
 {
-	signed char __res;
+	int __res;
 
 	while (1) {
 		if ((__res = *cs - *ct++) != 0 || !*cs++)
@@ -266,7 +266,7 @@ EXPORT_SYMBOL(strcmp);
  */
 int strncmp(const char *cs, const char *ct, size_t count)
 {
-	signed char __res = 0;
+	int __res = 0;
 
 	while (count) {
 		if ((__res = *cs - *ct++) != 0 || !*cs++)
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-11-18 21:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-17 16:51 [PATCH] strcmp: fix overflow error Uwe Kleine-König
2009-11-17 17:36 ` Andreas Schwab
2009-11-17 17:41 ` Linus Torvalds
2009-11-17 18:16   ` Michael Buesch
2009-11-17 18:40     ` Linus Torvalds
2009-11-17 20:34     ` Andreas Schwab
2009-11-17 18:55   ` Uwe Kleine-König
2009-11-17 19:02     ` Linus Torvalds
2009-11-17 19:12       ` Linus Torvalds
2009-11-17 19:19       ` Joe Perches
2009-11-18 21:31   ` [PATCH] strcmp: fix overflow and possibly signedness error Uwe Kleine-König

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.