From: Willy Tarreau Date: Sun, 9 Dec 2012 10:08:14 +0000 (+0100) Subject: BUG/MEDIUM: stick-tables: conversions to strings were broken in dev13 X-Git-Tag: v1.5-dev15~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f22180f1b658106c08e83918dec64843c52d3d7e;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: stick-tables: conversions to strings were broken in dev13 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. --- diff --git a/src/stick_table.c b/src/stick_table.c index b681a8b86b..52a58665ed 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -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;