Software /
code /
prosody
Comparison
plugins/mod_component.lua @ 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 |
parent | 5370:7838acadb0fa |
child | 5728:2ecf400b194a |
comparison
equal
deleted
inserted
replaced
5721:579c51cbc12c | 5724:a49f32e3d73b |
---|---|
7 -- | 7 -- |
8 | 8 |
9 module:set_global(); | 9 module:set_global(); |
10 | 10 |
11 local t_concat = table.concat; | 11 local t_concat = table.concat; |
12 local traceback = debug.traceback; | |
12 | 13 |
13 local logger = require "util.logger"; | 14 local logger = require "util.logger"; |
14 local sha1 = require "util.hashes".sha1; | 15 local sha1 = require "util.hashes".sha1; |
15 local st = require "util.stanza"; | 16 local st = require "util.stanza"; |
16 | 17 |
181 function stream_callbacks.streamclosed(session) | 182 function stream_callbacks.streamclosed(session) |
182 session.log("debug", "Received </stream:stream>"); | 183 session.log("debug", "Received </stream:stream>"); |
183 session:close(); | 184 session:close(); |
184 end | 185 end |
185 | 186 |
187 local function handleerr(err) log("error", "Traceback[component]: %s", traceback(tostring(err), 2)); end | |
186 function stream_callbacks.handlestanza(session, stanza) | 188 function stream_callbacks.handlestanza(session, stanza) |
187 -- Namespaces are icky. | 189 -- Namespaces are icky. |
188 if not stanza.attr.xmlns and stanza.name == "handshake" then | 190 if not stanza.attr.xmlns and stanza.name == "handshake" then |
189 stanza.attr.xmlns = xmlns_component; | 191 stanza.attr.xmlns = xmlns_component; |
190 end | 192 end |
211 session.log("warn", "Rejecting stanza with no 'to' address"); | 213 session.log("warn", "Rejecting stanza with no 'to' address"); |
212 session.send(st.error_reply(stanza, "modify", "bad-request", "Components MUST specify a 'to' address on stanzas")); | 214 session.send(st.error_reply(stanza, "modify", "bad-request", "Components MUST specify a 'to' address on stanzas")); |
213 return; | 215 return; |
214 end | 216 end |
215 end | 217 end |
216 return core_process_stanza(session, stanza); | 218 |
219 if stanza then | |
220 return xpcall(function () return core_process_stanza(session, stanza) end, handleerr); | |
221 end | |
217 end | 222 end |
218 | 223 |
219 --- Closing a component connection | 224 --- Closing a component connection |
220 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; | 225 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
221 local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; | 226 local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; |