From f2ae0768bf0802a2a5b63fb40568b4bd1186fe8b Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Mon, 22 Dec 2014 14:29:57 +0300 Subject: [PATCH] Bug #1403699: sysbench crash at script_lua.c:860 Added protection for syntax errors in Lua scripts when code in the top-level chunk (i.e. not in one of the functions) tries to access the database driver. --- sysbench/scripting/script_lua.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sysbench/scripting/script_lua.c b/sysbench/scripting/script_lua.c index 87faaf2..f8387ef 100644 --- a/sysbench/scripting/script_lua.c +++ b/sysbench/scripting/script_lua.c @@ -1101,10 +1101,18 @@ int sb_lua_rand_str(lua_State *L) sb_lua_ctxt_t *sb_lua_get_context(lua_State *L) { + sb_lua_ctxt_t *ctxt; + lua_pushlightuserdata(L, (void *)&sb_lua_ctxt_key); lua_gettable(L, LUA_REGISTRYINDEX); - return (sb_lua_ctxt_t *)lua_touserdata(L, -1); + ctxt = (sb_lua_ctxt_t *)lua_touserdata(L, -1); + + if (ctxt == NULL) + luaL_error(L, "Attempt to access database driver before it is initialized. " + "Check your script for syntax errors"); + + return ctxt; } /* Set a per-state interpreter context */