[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1258476700-21323-1-git-send-email-u.kleine-koenig@pengutronix.de>
Date: Tue, 17 Nov 2009 17:51:40 +0100
From: Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>
To: linux-kernel@...r.kernel.org
Cc: Michael Buesch <mb@...sch.de>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Andrew Morton <akpm@...ux-foundation.org>,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [PATCH] strcmp: fix overflow error
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@...gutronix.de>
Cc: Michael Buesch <mb@...sch.de>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Linus Torvalds <torvalds@...ux-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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists