]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: log an error if virXMLNodeContentString will return NULL
authorLaine Stump <laine@redhat.com>
Tue, 14 Jul 2020 04:21:28 +0000 (00:21 -0400)
committerLaine Stump <laine@redhat.com>
Wed, 5 Aug 2020 04:04:48 +0000 (00:04 -0400)
Many of our calls to xmlNodeGetContent() (which are now all via
virXMLNodeContentString() are failing to check for a NULL return. We
need to remedy that, but in order to make the remedy simpler, let's
log an error in virXMLNodeContentString(), so that the callers don't
all individually need to (since it would be the same error message for
all of them anyway).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virxml.c

index 27d22598eeafab988ffd23b0d32c1f22eac5b342..5315d4ff6fdfe2ebb2958558f595b1cc46113113 100644 (file)
@@ -538,7 +538,23 @@ virXMLPropStringLimit(xmlNodePtr node,
 char *
 virXMLNodeContentString(xmlNodePtr node)
 {
-    return (char *)xmlNodeGetContent(node);
+    char *ret = (char *)xmlNodeGetContent(node);
+
+    if (node->type !=  XML_ELEMENT_NODE) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("node '%s' has unexpected type %d"),
+                       node->name, node->type);
+        return NULL;
+    }
+
+    if (!ret) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("node '%s' has unexpected NULL content. This could be caused by malformed input, or a memory allocation failure"),
+                       node->name);
+        return NULL;
+    }
+
+    return ret;
 }