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.
This commit is contained in:
Willy Tarreau 2012-12-09 11:08:14 +01:00
parent 9cd7d6ccfe
commit f22180f1b6

View 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;