aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-08-19 21:56:33 +0100
committerMatthew Wild <mwild1@gmail.com>2018-08-19 21:56:33 +0100
commit028db90d4ba000f91d61a9b507105aea1379136d (patch)
tree39c97fae457df6b0b0fc7be6d30e6cd39b8114e6
parent5005ab3e55455158a557682a9bd4269549a7dfaa (diff)
downloadprosody-028db90d4ba000f91d61a9b507105aea1379136d.tar.gz
prosody-028db90d4ba000f91d61a9b507105aea1379136d.zip
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
-rw-r--r--spec/util_stanza_spec.lua7
-rw-r--r--util/stanza.lua6
2 files changed, 13 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index aabeeadc..383beae3 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -327,5 +327,12 @@ describe("util.stanza", function()
end);
assert.equal(3, #s.tags);
end);
+ it("errors on invalid data - #981", function ()
+ local s = st.message({}, "Hello");
+ s.tags[1] = st.clone(s.tags[1]);
+ assert.has_error_match(function ()
+ s:maptags(function () end);
+ end, "Invalid stanza");
+ end);
end);
end);
diff --git a/util/stanza.lua b/util/stanza.lua
index 11398179..f08baef7 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -217,6 +217,7 @@ end
function stanza_mt:maptags(callback)
local tags, curr_tag = self.tags, 1;
local n_children, n_tags = #self, #tags;
+ local max_iterations = n_children + 1;
local i = 1;
while curr_tag <= n_tags and n_tags > 0 do
@@ -236,6 +237,11 @@ function stanza_mt:maptags(callback)
curr_tag = curr_tag + 1;
end
i = i + 1;
+ if i > max_iterations then
+ -- COMPAT: Hopefully temporary guard against #981 while we
+ -- figure out the root cause
+ error("Invalid stanza state! Please report this error.");
+ end
end
return self;
end