Comparison

util/stanza.lua @ 10445:f53c03ab4357

util.stanza: Check that argument to error_reply is NOT a stanza of type error Replying to an error is Very Bad
author Kim Alvefur <zash@zash.se>
date Mon, 25 Nov 2019 20:52:03 +0100
parent 10444:4eab1f5a4f3b
child 10446:5c2d1b13537c
comparison
equal deleted inserted replaced
10444:4eab1f5a4f3b 10445:f53c03ab4357
448 448
449 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; 449 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
450 local function error_reply(orig, error_type, condition, error_message) 450 local function error_reply(orig, error_type, condition, error_message)
451 if not is_stanza(orig) then 451 if not is_stanza(orig) then
452 error("bad argument to error_reply: expected stanza, got "..type(orig)); 452 error("bad argument to error_reply: expected stanza, got "..type(orig));
453 elseif orig.attr.type == "error" then
454 error("bad argument to error_reply: got stanza of type error which must not be replied to");
453 end 455 end
454 local t = reply(orig); 456 local t = reply(orig);
455 t.attr.type = "error"; 457 t.attr.type = "error";
456 t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here 458 t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here
457 :tag(condition, xmpp_stanzas_attr):up(); 459 :tag(condition, xmpp_stanzas_attr):up();