From: Florent Bruneau Date: Wed, 17 Sep 2008 14:38:06 +0000 (+0200) Subject: Store param value length. Fix off-by-one. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=7e4bf3c72dfb5be45dcb6479c5fa69c0dde80449;p=apps%2Fpfixtools.git Store param value length. Fix off-by-one. Signed-off-by: Florent Bruneau --- diff --git a/postlicyd/config.c b/postlicyd/config.c index 20716b2..b563ef3 100644 --- a/postlicyd/config.c +++ b/postlicyd/config.c @@ -304,7 +304,8 @@ read_param_value: filter_param_t param; param.type = param_tokenize(key, key_len); if (param.type != ATK_UNKNOWN) { - param.value = m_strdup(value); + param.value = p_dupstr(value, value_len); + param.value_len = value_len; array_add(config->params, param); } } diff --git a/postlicyd/filter.c b/postlicyd/filter.c index a067ef3..dea4436 100644 --- a/postlicyd/filter.c +++ b/postlicyd/filter.c @@ -209,9 +209,7 @@ const filter_hook_t *filter_run(const filter_t *filter, const query_t *query) void filter_set_name(filter_t *filter, const char *name, ssize_t len) { - filter->name = p_new(char, len + 1); - memcpy(filter->name, name, len); - filter->name[len] = '\0'; + filter->name = p_dupstr(name, len); } bool filter_set_type(filter_t *filter, const char *type, ssize_t len) @@ -234,7 +232,8 @@ bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len, atokens[param.type], ftokens[filter->type]); return false; } - param.value = m_strdup(value); + param.value = p_dupstr(value, value_len); + param.value_len = value_len; array_add(filter->params, param); return true; } diff --git a/postlicyd/filter.h b/postlicyd/filter.h index e8319d3..f53b917 100644 --- a/postlicyd/filter.h +++ b/postlicyd/filter.h @@ -58,7 +58,8 @@ ARRAY(filter_hook_t) typedef struct filter_param_t { filter_param_id_t type; - char *value; + char *value; + ssize_t value_len; } filter_param_t; ARRAY(filter_param_t) @@ -186,30 +187,30 @@ const filter_hook_t *filter_run(const filter_t *filter, const query_t *query); case ATK_ ## Param: { \ char *next; \ (Dest) = strtol(param->value, &next, 10); \ - PARSE_CHECK(!*next, "invalid %s value %s", atokens[ATK_ ## Param], \ - param->value); \ + PARSE_CHECK(!*next, "invalid %s value %.*s", atokens[ATK_ ## Param], \ + param->value_len, param->value); \ } break #define FILTER_PARAM_PARSE_BOOLEAN(Param, Dest) \ case ATK_ ## Param: { \ - if (param->value[0] == '1' && param->value[1] == '\0') { \ + if (param->value_len == 1 && param->value[0] == '1') { \ (Dest) = true; \ - } else if (param->value[0] == '0' && param->value[1] == '\0') { \ + } else if (param->value_len == 1 && param->value[0] == '0') { \ (Dest) = false; \ - } else if (ascii_tolower(param->value[0]) == 't') { \ + } else if (param->value_len == 4 \ + && ascii_tolower(param->value[0]) == 't') { \ (Dest) = ascii_tolower(param->value[1]) == 'r' \ && ascii_tolower(param->value[2]) == 'u' \ - && ascii_tolower(param->value[3]) == 'e' \ - && !param->value[4]; \ - } else if (ascii_tolower(param->value[0]) == 'f') { \ + && ascii_tolower(param->value[3]) == 'e'; \ + } else if (param->value_len == 5 \ + && ascii_tolower(param->value[0]) == 'f') { \ (Dest) = ascii_tolower(param->value[1]) == 'a' \ && ascii_tolower(param->value[2]) == 'l' \ && ascii_tolower(param->value[3]) == 's' \ - && ascii_tolower(param->value[4]) == 'e' \ - && !param->value[5]; \ + && ascii_tolower(param->value[4]) == 'e'; \ } else { \ - PARSE_CHECK(false, "invalid %s value %s", atokens[ATK_ ## Param], \ - param->value); \ + PARSE_CHECK(false, "invalid %s value %.*s", atokens[ATK_ ## Param],\ + param->value_len, param->value); \ } \ } break diff --git a/postlicyd/rbl.c b/postlicyd/rbl.c index 748d40a..1bae4d8 100644 --- a/postlicyd/rbl.c +++ b/postlicyd/rbl.c @@ -305,8 +305,10 @@ static bool rbl_filter_constructor(filter_t *filter) array_add(data->weights, weight); break; } - current = p + 1; - p = m_strchrnul(current, ':'); + if (i != 2) { + current = p + 1; + p = m_strchrnul(current, ':'); + } } } break; diff --git a/postlicyd/strlist.c b/postlicyd/strlist.c index 25ed069..dee9269 100644 --- a/postlicyd/strlist.c +++ b/postlicyd/strlist.c @@ -219,13 +219,16 @@ static bool strlist_filter_constructor(filter_t *filter) trie = strlist_create(current, reverse, lock); PARSE_CHECK(trie != NULL, "cannot load string list from %s", current); + trie_inspect(trie, false); array_add(config->tries, trie); array_add(config->weights, weight); array_add(config->reverses, reverse); break; } - current = p + 1; - p = m_strchrnul(current, ':'); + if (i != 3) { + current = p + 1; + p = m_strchrnul(current, ':'); + } } } break;