changeset 472:cf66b8733a66

Use protected call (pcall) for proccessed files with embedded Lua code.
author Aleksandr Rybalko <ray@ddteam.net>
date Mon, 24 Sep 2012 14:24:52 +0300
parents a581dc308cff
children 7a9c32f8fc56
files profiles/lua_web_ui/files/etc/www/httpd.lua
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/profiles/lua_web_ui/files/etc/www/httpd.lua	Mon Sep 24 14:23:30 2012 +0300
+++ b/profiles/lua_web_ui/files/etc/www/httpd.lua	Mon Sep 24 14:24:52 2012 +0300
@@ -493,7 +493,7 @@
 			    " " .. urlEncode(path));
 			retcode = "500";
 		else
-			t = code();
+			st, t = pcall(code);
 		end
 	end
 	client:send(t);
@@ -509,11 +509,16 @@
 
 	match, _, code = string.find(s, "^code%:(.*)$");
 	if match then
-		local func, err = loadstring("return " .. code);
+		local func, err = assert(loadstring("return " .. code));
 		if not func then
 			return err;
 		end
-		return func();
+		local status, ret = pcall(func);
+		if status == false then
+			print(code, " failed");
+			return "";
+		end
+		return (ret);
 	else
 		node = c:getNode(s);
 		if node then