]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: chunk: Fix function chunk_strcmp and chunk_strcasecmp match a substring.
authorEmeric Brun <ebrun@exceliance.fr>
Fri, 9 May 2014 15:11:07 +0000 (17:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 May 2014 17:16:13 +0000 (19:16 +0200)
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.

src/chunk.c

index d7d8501d638101a49a130335e34fd0e2933e4270..3c1cfdffcbca647825e1479b0c0f74a5a4b157ff 100644 (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;