aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-14 22:11:43 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-14 22:11:43 +0100
commit51e0796dcfb90c8431ee39b54448dcc8a591d535 (patch)
treedf63c60c3ef20ac5b514f74ffbe159878dbbc390 /src/lua
parent59f56bfbf59492ef987bd702c3ce59cc113f47c0 (diff)
downloadrspamd-51e0796dcfb90c8431ee39b54448dcc8a591d535.tar.gz
rspamd-51e0796dcfb90c8431ee39b54448dcc8a591d535.zip
Fix parsing of lua tables.
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.c11
-rw-r--r--src/lua/lua_config.c8
2 files changed, 12 insertions, 7 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 209e68fb1..bea2f0a58 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -629,10 +629,10 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos,
state = read_arg;
keylen = p - key;
}
- else if (*p == '*') {
+ else if (*p == '*' && key == NULL) {
required = TRUE;
}
- else {
+ else if (key == NULL) {
key = p;
}
p ++;
@@ -787,15 +787,16 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos,
break;
case read_semicolon:
- if (*p == ':') {
+ if (*p == ';' || p == end) {
state = read_key;
key = NULL;
keylen = 0;
failed = FALSE;
}
else {
- g_set_error (err, lua_error_quark (), 2, "bad format string: %s",
- extraction_pattern);
+ g_set_error (err, lua_error_quark (), 2, "bad format string: %s,"
+ " at char %c, position %d",
+ extraction_pattern, *p, (int)(p - extraction_pattern));
va_end (ap);
return FALSE;
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index a26b6b4aa..07e10916a 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1220,7 +1220,7 @@ lua_config_set_metric_symbol (lua_State * L)
if (lua_type (L, 2) == LUA_TTABLE) {
if (!rspamd_lua_parse_table_arguments (L, 2, &err,
- "name=*S;score=N;description=S;"
+ "*name=S;score=N;description=S;"
"group=S;one_shot=B;metric=S",
&name, &weight, &description,
&group, &one_shot, &metric_name)) {
@@ -1248,12 +1248,16 @@ lua_config_set_metric_symbol (lua_State * L)
}
}
+ if (metric_name == NULL) {
+ metric_name = DEFAULT_METRIC;
+ }
+
metric = g_hash_table_lookup (cfg->metrics, metric_name);
if (metric == NULL) {
msg_err_config ("metric named %s is not defined", metric_name);
}
- else if (name != NULL && weight > 0) {
+ else if (name != NULL && weight != 0) {
rspamd_config_add_metric_symbol (cfg, metric_name, name,
weight, description, group, one_shot, FALSE);
}