Skip to content

Commit 055b382

Browse files
committed
[CVE-2025-24928] Fix stack-buffer-overflow in xmlSnprintfElements
Fixes #847.
1 parent a6bf2cb commit 055b382

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

valid.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5005,26 +5005,26 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) {
50055005
return;
50065006
}
50075007
switch (cur->type) {
5008-
case XML_ELEMENT_NODE:
5008+
case XML_ELEMENT_NODE: {
5009+
int qnameLen = xmlStrlen(cur->name);
5010+
5011+
if ((cur->ns != NULL) && (cur->ns->prefix != NULL))
5012+
qnameLen += xmlStrlen(cur->ns->prefix) + 1;
5013+
if (size - len < qnameLen + 10) {
5014+
if ((size - len > 4) && (buf[len - 1] != '.'))
5015+
strcat(buf, " ...");
5016+
return;
5017+
}
50095018
if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
5010-
if (size - len < xmlStrlen(cur->ns->prefix) + 10) {
5011-
if ((size - len > 4) && (buf[len - 1] != '.'))
5012-
strcat(buf, " ...");
5013-
return;
5014-
}
50155019
strcat(buf, (char *) cur->ns->prefix);
50165020
strcat(buf, ":");
50175021
}
5018-
if (size - len < xmlStrlen(cur->name) + 10) {
5019-
if ((size - len > 4) && (buf[len - 1] != '.'))
5020-
strcat(buf, " ...");
5021-
return;
5022-
}
50235022
if (cur->name != NULL)
50245023
strcat(buf, (char *) cur->name);
50255024
if (cur->next != NULL)
50265025
strcat(buf, " ");
50275026
break;
5027+
}
50285028
case XML_TEXT_NODE:
50295029
if (xmlIsBlankNode(cur))
50305030
break;

0 commit comments

Comments
 (0)