]> git.kaiwu.me - njs.git/commitdiff
XML: ignore DTD attribute declarations in removeAttribute()
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 2 Dec 2026 00:23:11 +0000 (16:23 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 3 Dec 2026 01:27:35 +0000 (17:27 -0800)
Previously, njs_xml_node_attr_handler() and qjs_xml_node_attr_handler()
passed the result of xmlHasProp() directly to xmlRemoveProp().  Because
xmlHasProp() can return an XML_ATTRIBUTE_DECL node from the DTD when
the element does not have an own attribute of that name, xmlRemoveProp()
read past the end of the declaration structure.

Only call xmlRemoveProp() when xmlHasProp() returns an
XML_ATTRIBUTE_NODE.

The issues were introduced in 7d656627 (0.7.11) and cec9a165 (0.8.10).

external/njs_xml_module.c
external/qjs_xml_module.c

index cacbd091e9816aa80676c39f4b9db56cd6596e71..e24e71255fcfe3483f8fac5493d3b4d3d24aa370 100644 (file)
@@ -1212,7 +1212,7 @@ njs_xml_node_attr_handler(njs_vm_t *vm, xmlNode *current, njs_str_t *name,
 
         attr = xmlHasProp(current, name_c);
 
-        if (attr != NULL) {
+        if (attr != NULL && attr->type == XML_ATTRIBUTE_NODE) {
             xmlRemoveProp(attr);
         }
 
index d5621924d170ee1ae473e82f552927466ced91fc..ae2b8b33de5fb8323a000dc45b48c5d8b747c7bf 100644 (file)
@@ -760,7 +760,7 @@ qjs_xml_node_attr_modify(JSContext *cx, JSValue current, const u_char *name,
     if (JS_IsNullOrUndefined(setval)) {
         attr = xmlHasProp(node->node, name);
 
-        if (attr != NULL) {
+        if (attr != NULL && attr->type == XML_ATTRIBUTE_NODE) {
             xmlRemoveProp(attr);
         }