lua: fix crash on stack overflow: call lua_pop() for values returned by lua functions (bug #38510)

This commit is contained in:
Sebastien Helleu 2013-03-13 18:27:55 +01:00
parent 81cc688166
commit 3fb123510a
2 changed files with 32 additions and 28 deletions

View File

@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.4.1-dev, 2013-03-12
v0.4.1-dev, 2013-03-13
This document lists all changes for each version.
@ -54,6 +54,8 @@ Version 0.4.1 (under dev!)
the first server in the list)
* irc: add color in output of /names when result is on server buffer (channel
not joined) (bug #38070)
* lua: fix crash on stack overflow: call lua_pop() for values returned by lua
functions (bug #38510)
* perl: simplify code to load scripts
* relay: add message "_nicklist_diff" (differences between old and current
nicklist)

View File

@ -198,7 +198,34 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
}
}
if (lua_pcall (lua_current_interpreter, argc, 1, 0) != 0)
ret_value = NULL;
if (lua_pcall (lua_current_interpreter, argc, 1, 0) == 0)
{
if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
{
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
{
ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = lua_tonumber (lua_current_interpreter, -1);
ret_value = ret_i;
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
{
ret_value = weechat_lua_tohashtable (lua_current_interpreter, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
}
else
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, function);
}
}
else
{
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to run function \"%s\""),
@ -207,34 +234,9 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
weechat_gettext ("%s%s: error: %s"),
weechat_prefix ("error"), LUA_PLUGIN_NAME,
lua_tostring (lua_current_interpreter, -1));
lua_current_script = old_lua_current_script;
lua_current_interpreter = old_lua_current_interpreter;
return NULL;
}
if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
{
ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = lua_tonumber (lua_current_interpreter, -1);
ret_value = ret_i;
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
{
ret_value = weechat_lua_tohashtable (lua_current_interpreter, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
}
else
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, function);
lua_current_script = old_lua_current_script;
lua_current_interpreter = old_lua_current_interpreter;
return NULL;
}
lua_pop (lua_current_interpreter, 1);
lua_current_script = old_lua_current_script;
lua_current_interpreter = old_lua_current_interpreter;