]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: stick-tables: conversions to strings were broken in dev13
authorWilly Tarreau <w@1wt.eu>
Sun, 9 Dec 2012 10:08:14 +0000 (11:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 9 Dec 2012 10:10:30 +0000 (11:10 +0100)
Commit 07115412 (MEDIUM: stick-table: allocate the table key...) broke
conversion of samples to strings for stick tables, because if replaced
char buf[BUFSIZE] with char buf[0] and the string converters use sizeof
on this part. Note that sizeof was wrong as well but at least it used
to work.

Fix this by making use of the len parameter instead of sizeof.

src/stick_table.c

index b681a8b86b5fa2039eab2503514ed8adb3daa0bd..52a58665ed21f709407116e3fd5a8236c51c666f 100644 (file)
@@ -497,7 +497,7 @@ static void *k_str2str(struct sample *smp, union stktable_key_data *kdata, size_
 
 static void *k_ip2str(struct sample *smp, union stktable_key_data *kdata, size_t *len)
 {
-       if (!inet_ntop(AF_INET, &smp->data.ipv4, kdata->buf, sizeof(kdata->buf)))
+       if (!inet_ntop(AF_INET, &smp->data.ipv4, kdata->buf, *len))
                return NULL;
 
        *len = strlen((const char *)kdata->buf);
@@ -508,20 +508,21 @@ static void *k_bin2str(struct sample *smp, union stktable_key_data *kdata, size_
 {
        unsigned char c;
        int ptr = 0;
+       int max = *len;
+       int size = 0;
 
-       *len = 0;
-       while (ptr < smp->data.str.len && *len <= sizeof(kdata->buf) - 2) {
+       while (ptr < smp->data.str.len && size <= max - 2) {
                c = smp->data.str.str[ptr++];
-               kdata->buf[(*len)++] = hextab[(c >> 4) & 0xF];
-               kdata->buf[(*len)++] = hextab[c & 0xF];
+               kdata->buf[size++] = hextab[(c >> 4) & 0xF];
+               kdata->buf[size++] = hextab[c & 0xF];
        }
-
+       *len = size;
        return (void *)kdata->buf;
 }
 
 static void *k_ipv62str(struct sample *smp, union stktable_key_data *kdata, size_t *len)
 {
-       if (!inet_ntop(AF_INET6, &smp->data.ipv6, kdata->buf, sizeof(kdata->buf)))
+       if (!inet_ntop(AF_INET6, &smp->data.ipv6, kdata->buf, *len))
                return NULL;
 
        *len = strlen((const char *)kdata->buf);
@@ -532,7 +533,7 @@ static void *k_int2str(struct sample *smp, union stktable_key_data *kdata, size_
 {
        void *key;
 
-       key = (void *)ultoa_r(smp->data.uint,  kdata->buf,  sizeof(kdata->buf));
+       key = (void *)ultoa_r(smp->data.uint, kdata->buf, *len);
        if (!key)
                return NULL;