From: Vsevolod Stakhov Date: Mon, 14 Sep 2015 21:11:43 +0000 (+0100) Subject: Fix parsing of lua tables. X-Git-Tag: 1.0.0~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51e0796dcfb90c8431ee39b54448dcc8a591d535;p=thirdparty%2Frspamd.git Fix parsing of lua tables. --- diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 209e68fb1d..bea2f0a581 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 a26b6b4aab..07e10916a1 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); }