diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-03 16:44:27 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-03 16:44:27 +0100 |
commit | b18c9d7e6132a75c2e2b52eaadfe32adf5debf5d (patch) | |
tree | 80a725f841e34274bf47ac9f59c51cdfebe329bf /src/lua/lua_logger.c | |
parent | e5b7873f94e4eaf15e136442237752cba005ed3a (diff) | |
download | rspamd-b18c9d7e6132a75c2e2b52eaadfe32adf5debf5d.tar.gz rspamd-b18c9d7e6132a75c2e2b52eaadfe32adf5debf5d.zip |
Fix lua logger arguments parsing.
Diffstat (limited to 'src/lua/lua_logger.c')
-rw-r--r-- | src/lua/lua_logger.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index 19ce3df8e..ab1f49e4a 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -429,7 +429,8 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) gchar *d; const gchar *s, *c, *clsname, *uid = NULL; gsize remain, r; - guint arg_num = 0, fmt_pos; + guint arg_num = 0, fmt_pos, cur_arg; + bool num_arg = false; enum { copy_char = 0, got_percent, @@ -492,6 +493,7 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) s = lua_tostring (L, fmt_pos); c = s; + cur_arg = fmt_pos + 1; if (s == NULL) { return 0; @@ -510,7 +512,7 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) } break; case got_percent: - if (g_ascii_isdigit (*s)) { + if (g_ascii_isdigit (*s) || *s == 's') { state = parse_arg_num; c = s; } @@ -522,9 +524,20 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) case parse_arg_num: if (g_ascii_isdigit (*s)) { s++; + num_arg = true; } else { - arg_num = strtoul (c, NULL, 10); + if (num_arg) { + arg_num = strtoul (c, NULL, 10); + arg_num += fmt_pos - 1; + /* Update the current argument */ + cur_arg = arg_num + 1; + } + else { + /* We have non numeric argument, e.g. %s */ + arg_num = cur_arg ++; + s ++; + } if (arg_num < 1 || arg_num > (guint) lua_gettop (L) + 1) { msg_err ("wrong argument number: %ud", arg_num); @@ -549,7 +562,14 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) } if (state == parse_arg_num) { - arg_num = strtoul (c, NULL, 10); + if (num_arg) { + arg_num = strtoul (c, NULL, 10); + arg_num += fmt_pos - 1; + } + else { + /* We have non numeric argument, e.g. %s */ + arg_num = cur_arg; + } if (arg_num < 1 || arg_num > (guint) lua_gettop (L) + 1) { msg_err ("wrong argument number: %ud", arg_num); |