From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Christophe Fergeau <cfergeau@redhat.com>
Date: Tue, 25 Jul 2017 17:36:05 +0200
Subject: [PATCH] resource: Fix ovirt_resource_rest_call_sync() crash on 404
When the REST call fails, we do not always get an XML answer from oVirt
describing the failure in more details. In particular, this is the case
when we hit a 404. In such situations, we'd be crashing because we'd
attempt to dereference a NULL pointer.
---
govirt/ovirt-resource.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
index 0c750ac..0f4a129 100644
--- a/govirt/ovirt-resource.c
+++ b/govirt/ovirt-resource.c
@@ -485,16 +485,17 @@ G_GNUC_INTERNAL RestXmlNode *ovirt_resource_rest_call_sync(OvirtRestCall *call,
GError *local_error = NULL;
root = ovirt_rest_xml_node_from_call(REST_PROXY_CALL(call));
- ovirt_utils_gerror_from_xml_fault(root, &local_error);
+ if (root != NULL) {
+ ovirt_utils_gerror_from_xml_fault(root, &local_error);
+ rest_xml_node_unref(root);
+ }
if (local_error != NULL) {
g_clear_error(error);
g_warning("Error while updating resource");
g_warning("message: %s", local_error->message);
g_propagate_error(error, local_error);
}
- if (root != NULL) {
- rest_xml_node_unref(root);
- }
+ g_warn_if_fail(error == NULL || *error != NULL);
return NULL;
}