From c645ed74852cd766bcf6b815556074086ebce7e0 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 15 Apr 2007 02:20:41 +0300 Subject: [PATCH] Bug 945: Don't crash if the error message is not a string. --- src/scripting/lua/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c index 830676b5..fcd71764 100644 --- a/src/scripting/lua/core.c +++ b/src/scripting/lua/core.c @@ -71,7 +71,13 @@ static void handle_ref(LS, struct session *ses, int func_ref, static int l_alert(LS) { - alert_lua_error((unsigned char *) lua_tostring(S, 1)); + unsigned char *msg = (unsigned char *) lua_tostring(S, 1); + + /* Don't crash if a script calls e.g. error(nil) or error(error). */ + if (msg == NULL) + msg = "(cannot convert the error message to a string)"; + + alert_lua_error(msg); return 0; }