]> git.kaiwu.me - njs.git/commitdiff
XML: guard against content allocation failure
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 22 Sep 2026 04:03:48 +0000 (21:03 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 25 Sep 2026 23:00:29 +0000 (16:00 -0700)
Report a memory error when libxml cannot allocate node content instead of
passing a NULL pointer to the string conversion path.

external/njs_xml_module.c

index 08979becb40acb36c8ca6e29ea0eb406da773fb5..e745a5d6d6349e64dbd900582dab993490e177b0 100644 (file)
@@ -988,6 +988,11 @@ njs_xml_node_ext_text(njs_vm_t *vm, njs_object_prop_t *unused, uint32_t unused1,
 
     if (retval != NULL && setval == NULL) {
         content.start = xmlNodeGetContent(current);
+        if (njs_slow_path(content.start == NULL)) {
+            njs_vm_memory_error(vm);
+            return NJS_ERROR;
+        }
+
         ret = njs_vm_value_string_create(vm, retval, content.start,
                                          njs_strlen(content.start));