]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-lua - Use lua_type to detect type
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 29 Oct 2018 07:52:37 +0000 (09:52 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 14 Nov 2018 12:20:55 +0000 (14:20 +0200)
Using lua_isnumber to detect numbers also considers
convertible strings as numbers.

src/auth/db-lua.c

index b2f4a1ef02948316d6b7af071f8f5bd32516bd01..9c3df035b959e573d9591765f8d5705c045ae883 100644 (file)
@@ -480,18 +480,24 @@ static void auth_lua_export_table(struct dlua_script *script, struct auth_reques
        while (lua_next(script->L, -2) != 0) {
                const char *key = t_strdup(lua_tostring(script->L, -2));
                const char *value;
-               if (lua_isnumber(script->L, -1)) {
+               int type = lua_type(script->L, -1);
+               switch(type) {
+               case LUA_TNUMBER:
                        value = dec2str(lua_tointeger(script->L, -1));
-               } else if (lua_isboolean(script->L, -1)) {
+                       break;
+               case LUA_TBOOLEAN:
                        value = lua_toboolean(script->L, -1) ? "yes" : "no";
-               } else if (lua_isstring(script->L, -1)) {
+                       break;
+               case LUA_TSTRING:
                        value = t_strdup(lua_tostring(script->L, -1));
-               } else if (lua_isnil(script->L, -1)) {
+                       break;
+               case LUA_TNIL:
                        value = "";
-               } else {
+                       break;
+               default:
                        auth_request_log_warning(req, AUTH_SUBSYS_DB,
-                                                "db-lua: '%s' has invalid value - ignoring",
-                                                key);
+                                                "db-lua: '%s' has invalid value type %s - ignoring",
+                                                key, lua_typename(script->L, -1));
                        value = "";
                }