Changeset

10444:4eab1f5a4f3b

util.stanza: Check that argument to error_reply is a stanza
author Kim Alvefur <zash@zash.se>
date Mon, 25 Nov 2019 20:52:01 +0100
parents 10443:f28718f46196
children 10445:f53c03ab4357
files spec/util_stanza_spec.lua util/stanza.lua
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 ()
--- 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