From: Aki Tuomi Date: Mon, 29 Oct 2018 07:52:37 +0000 (+0200) Subject: auth: db-lua - Use lua_type to detect type X-Git-Tag: 2.3.9~1148 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80fa56296c1e84ff0fc65571d80a6fc2640e40ac;p=thirdparty%2Fdovecot%2Fcore.git auth: db-lua - Use lua_type to detect type Using lua_isnumber to detect numbers also considers convertible strings as numbers. --- diff --git a/src/auth/db-lua.c b/src/auth/db-lua.c index b2f4a1ef02..9c3df035b9 100644 --- a/src/auth/db-lua.c +++ b/src/auth/db-lua.c @@ -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 = ""; }