Changeset

5724:a49f32e3d73b

mod_component: xpcall() stanza processing, as per other listeners, preventing potentially harmful 'top-level errors'
author Matthew Wild <mwild1@gmail.com>
date Mon, 08 Jul 2013 21:38:08 +0100
parents 5721:579c51cbc12c
children 5725:c4200292758c 5726:3bccc68a38e3
files plugins/mod_component.lua
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_component.lua	Sat Jun 29 22:40:10 2013 +0200
+++ b/plugins/mod_component.lua	Mon Jul 08 21:38:08 2013 +0100
@@ -9,6 +9,7 @@
 module:set_global();
 
 local t_concat = table.concat;
+local traceback = debug.traceback;
 
 local logger = require "util.logger";
 local sha1 = require "util.hashes".sha1;
@@ -183,6 +184,7 @@
 	session:close();
 end
 
+local function handleerr(err) log("error", "Traceback[component]: %s", traceback(tostring(err), 2)); end
 function stream_callbacks.handlestanza(session, stanza)
 	-- Namespaces are icky.
 	if not stanza.attr.xmlns and stanza.name == "handshake" then
@@ -213,7 +215,10 @@
 			return;
 		end
 	end
-	return core_process_stanza(session, stanza);
+
+	if stanza then
+		return xpcall(function () return core_process_stanza(session, stanza) end, handleerr);
+	end
 end
 
 --- Closing a component connection