]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix parsing of lua tables.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Sep 2015 21:11:43 +0000 (22:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Sep 2015 21:11:43 +0000 (22:11 +0100)
src/lua/lua_common.c
src/lua/lua_config.c

index 209e68fb1db74bdd9442e1d5975d81308242d73a..bea2f0a5815b322c408cf5a79d629b595c55e41c 100644 (file)
@@ -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;
index a26b6b4aabafc2d34818b57794712f2811eaf9c2..07e10916a1fbec80ac8b6a74e0a91f4c19236d70 100644 (file)
@@ -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);
                }