aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-11-11 16:09:55 +0100
committerKim Alvefur <zash@zash.se>2020-11-11 16:09:55 +0100
commitf69303f26474c9d57cfe16f087fdbb37df36afbf (patch)
treea223774447667ef521ede13035939ef83a7a25e3
parentd741e95ccd91fc4d156f8c21e20b1b5b4bebdc5c (diff)
parent8328e6681e7a999c59be05c9e08158a0cf9f95d0 (diff)
downloadprosody-f69303f26474c9d57cfe16f087fdbb37df36afbf.tar.gz
prosody-f69303f26474c9d57cfe16f087fdbb37df36afbf.zip
Merge 0.11->trunk
-rw-r--r--spec/util_stanza_spec.lua1
-rw-r--r--util/stanza.lua10
2 files changed, 10 insertions, 1 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index 535f783b..b9ab1e31 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -297,6 +297,7 @@ describe("util.stanza", function()
["number"] = 1234, ["table"] = {};
["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80);
["nil"] = "nil"; ["boolean"] = true;
+ ["control characters"] = "\0\1\2\3";
};
for value_type, value in pairs(invalid_names) do
diff --git a/util/stanza.lua b/util/stanza.lua
index 94815346..85f047f8 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -45,6 +45,10 @@ local _ENV = nil;
local stanza_mt = { __name = "stanza" };
stanza_mt.__index = stanza_mt;
+local function valid_xml_cdata(str, attr)
+ return not s_find(str, attr and "[^\1\9\10\13\20-~\128-\247]" or "[^\9\10\13\20-~\128-\247]");
+end
+
local function check_name(name, name_type)
if type(name) ~= "string" then
error("invalid "..name_type.." name: expected string, got "..type(name));
@@ -52,6 +56,8 @@ local function check_name(name, name_type)
error("invalid "..name_type.." name: empty string");
elseif s_find(name, "[<>& '\"]") then
error("invalid "..name_type.." name: contains invalid characters");
+ elseif not valid_xml_cdata(name, name_type == "attribute") then
+ error("invalid "..name_type.." name: contains control characters");
elseif not valid_utf8(name) then
error("invalid "..name_type.." name: contains invalid utf8");
end
@@ -60,7 +66,9 @@ end
local function check_text(text, text_type)
if type(text) ~= "string" then
error("invalid "..text_type.." value: expected string, got "..type(text));
- elseif not valid_utf8(text) then
+ elseif not valid_xml_cdata(text) then
+ error("invalid "..text_type.." value: contains control characters");
+ elseif not valid_utf8(text, false) then
error("invalid "..text_type.." value: contains invalid utf8");
end
end