]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] stick-table: correctly terminate string keys during lookups
authorWilly Tarreau <w@1wt.eu>
Sun, 2 Jan 2011 18:31:23 +0000 (19:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Jan 2011 19:12:10 +0000 (20:12 +0100)
If a key to be looked up is extracted from data without being padded
and if it matches the beginning of another stored key, it is not
found in subsequent lookups because it does not end with a zero.

This bug was discovered and diagnosed by David Cournapeau.

src/stick_table.c

index 7c9ad8da0dfadd135a7fa02c2ea57564c0d45d0b..40b2bff07e08ada33666a18c5276b8f71eeadb89 100644 (file)
@@ -560,7 +560,13 @@ struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, st
        if (!static_table_key.key)
                return NULL;
 
-       if ((static_table_key.key_len < t->key_size) && (t->type != STKTABLE_TYPE_STRING)) {
+       if (t->type == STKTABLE_TYPE_STRING) {
+               /* The string MUST be terminated by a '\0' after the key_len bytes */
+               if (static_table_key.key_len > t->key_size - 1)
+                       static_table_key.key_len = t->key_size - 1;
+               ((char *)static_table_key.key)[static_table_key.key_len] = 0;
+       }
+       else if (static_table_key.key_len < t->key_size) {
                /* need padding with null */
 
                /* assume static_table_key.key_len is less than sizeof(static_table_key.data.buf)