# HG changeset patch # User Kim Alvefur # Date 1574711521 -3600 # Node ID 4eab1f5a4f3b112f33c48b90ff8af3e9233bb21f # Parent f28718f46196d1f68968193e892fed1c4d1f39ba util.stanza: Check that argument to error_reply is a stanza diff -r f28718f46196 -r 4eab1f5a4f3b spec/util_stanza_spec.lua --- a/spec/util_stanza_spec.lua Mon Nov 25 20:46:55 2019 +0100 +++ b/spec/util_stanza_spec.lua Mon Nov 25 20:52:01 2019 +0100 @@ -214,6 +214,12 @@ assert.are.equal(#r.tags, 1); assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); end); + + it("should reject not-stanzas", function () + assert.has.error_match(function () + st.error_reply(not "a stanza", "modify", "bad-request"); + end, "expected stanza"); + end); end); describe("should reject #invalid", function () diff -r f28718f46196 -r 4eab1f5a4f3b util/stanza.lua --- a/util/stanza.lua Mon Nov 25 20:46:55 2019 +0100 +++ b/util/stanza.lua Mon Nov 25 20:52:01 2019 +0100 @@ -448,6 +448,9 @@ local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; local function error_reply(orig, error_type, condition, error_message) + if not is_stanza(orig) then + error("bad argument to error_reply: expected stanza, got "..type(orig)); + end local t = reply(orig); t.attr.type = "error"; t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here