Messages in this thread Patch in this message | | | From | Uwe Kleine-König <> | Subject | [PATCH] strcmp: fix overflow error | Date | Tue, 17 Nov 2009 17:51:40 +0100 |
| |
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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |