Ha! This is a very interesting bug.

I copied strcasecmp() from userland to the kernel and it didn't worked!
I started to debug the problem and I find out that this line:

	while (tolower(*us1) == tolower(*us2++)) {

was adding _3_ bytes to 'us2' pointer. Am I loosing my minds here?!...
No, in-kernel tolower() is a macro which uses its argument three times.
Bad tolower(9), no cookie.
This commit is contained in:
Pawel Jakub Dawidek 2005-08-08 19:38:00 +00:00
parent 417ab24f78
commit 57169160b0

View File

@ -43,11 +43,12 @@ strcasecmp(const char *s1, const char *s2)
{ {
const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2; const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2;
while (tolower(*us1) == tolower(*us2++)) { while (tolower(*us1) == tolower(*us2)) {
if (*us1++ == '\0') if (*us1++ == '\0')
return (0); return (0);
us2++;
} }
return (tolower(*us1) - tolower(*--us2)); return (tolower(*us1) - tolower(*us2));
} }
int int
@ -59,10 +60,11 @@ strncasecmp(const char *s1, const char *s2, size_t n)
const u_char *us2 = (const u_char *)s2; const u_char *us2 = (const u_char *)s2;
do { do {
if (tolower(*us1) != tolower(*us2++)) if (tolower(*us1) != tolower(*us2))
return (tolower(*us1) - tolower(*--us2)); return (tolower(*us1) - tolower(*us2));
if (*us1++ == '\0') if (*us1++ == '\0')
break; break;
us2++;
} while (--n != 0); } while (--n != 0);
} }
return (0); return (0);