Commit 587474a158 for freeswitch.com
commit 587474a1584488f0c04201e6e61efe76aa5bda01
Author: Dmitry Verenitsin <morbit85@gmail.com>
Date: Sat Aug 8 19:07:32 2026 +0500
Merge commit from fork
diff --git a/src/switch_xml.c b/src/switch_xml.c
index 027b8f093b..e92134d522 100644
--- a/src/switch_xml.c
+++ b/src/switch_xml.c
@@ -658,7 +658,9 @@ static char *switch_xml_decode(char *s, char **ent, char t)
for (b = 0; ent[b] && strncmp(s + 1, ent[b], strlen(ent[b])); b += 2); /* find entity in entity list */
if (ent[b++]) { /* found a match */
- if ((c = (unsigned long) strlen(ent[b])) - 1 > (e = strchr(s, ';')) - s) {
+ c = (unsigned long) strlen(ent[b]);
+ e = strchr(s, ';');
+ if (c && c - 1 > (unsigned long)(e - s)) {
l = (d = (unsigned long) (s - r)) + c + (unsigned long) strlen(e); /* new length */
if (l) {
if (r == m) {
diff --git a/tests/unit/switch_xml.c b/tests/unit/switch_xml.c
index 0e5fc861d5..c1a5559872 100644
--- a/tests/unit/switch_xml.c
+++ b/tests/unit/switch_xml.c
@@ -250,6 +250,37 @@ FST_MINCORE_BEGIN("./conf")
switch_xml_free(xml);
}
FST_TEST_END()
+
+ FST_TEST_BEGIN(test_empty_entity_decode)
+ {
+ const char *text =
+ "<xml><!DOCTYPE Response ["
+ "<!ENTITY empty \"\">"
+ "<!ENTITY name \"World\">"
+ "]><Response><Say>Hello∅, &name;∅!</Say></Response></xml>";
+ switch_xml_t xml = NULL;
+ char *xml_string = NULL;
+
+ xml = switch_xml_parse_str_dynamic((char *)text, SWITCH_TRUE);
+ if (!xml) {
+ fst_fail("failed to parse XML with empty entity");
+ goto test_empty_entity_decode_done;
+ }
+
+ xml_string = switch_xml_toxml_ex(xml, SWITCH_FALSE, SWITCH_FALSE);
+ if (!xml_string) {
+ fst_fail("failed to serialize parsed XML");
+ goto test_empty_entity_decode_done;
+ }
+
+ fst_check_string_equals(xml_string,
+ "<xml>\n <Response>\n <Say>Hello, World!</Say>\n </Response>\n</xml>\n");
+
+test_empty_entity_decode_done:
+ free(xml_string);
+ if (xml) switch_xml_free(xml);
+ }
+ FST_TEST_END()
}
FST_SUITE_END()
}