BUG/MINOR: chunk: Fix function chunk_strcmp and chunk_strcasecmp match a substring.

They could match different strings as equal if the chunk was shorter
than the string. Those functions are currently only used for SSL's
certificate DN entry extract.
This commit is contained in:
Emeric Brun 2014-05-09 17:11:07 +02:00 committed by Willy Tarreau
parent afb768340c
commit 78bd4038d7

View File

@ -207,8 +207,10 @@ int chunk_strcmp(const struct chunk *chk, const char *str)
int diff = 0;
do {
if (--len < 0)
if (--len < 0) {
diff = (unsigned char)0 - (unsigned char)*str;
break;
}
diff = (unsigned char)*(s1++) - (unsigned char)*(str++);
} while (!diff);
return diff;
@ -225,8 +227,10 @@ int chunk_strcasecmp(const struct chunk *chk, const char *str)
int diff = 0;
do {
if (--len < 0)
if (--len < 0) {
diff = (unsigned char)0 - (unsigned char)*str;
break;
}
diff = (unsigned char)*s1 - (unsigned char)*str;
if (unlikely(diff)) {
unsigned int l = (unsigned char)*s1;