[libgovirt] utils: Check for valid data before calling rest_xml_parser_parse_from_data()
- From: Eduardo de Barros Lima <eblima src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] utils: Check for valid data before calling rest_xml_parser_parse_from_data()
- Date: Wed, 27 Mar 2019 18:38:47 +0000 (UTC)
commit 56bdee0fc7a82ba15c9b3655a7ef1dbb6c03eb97
Author: Eduardo Lima (Etrunko) <etrunko redhat com>
Date: Mon Feb 4 15:58:40 2019 -0200
utils: Check for valid data before calling rest_xml_parser_parse_from_data()
In the case of HTTP errors, such as a invalid TLS certificate, the
returned data is NULL, and the code in librest does not check for the
pointer being valid, causing a segfault.
The users of this function have been updated to check for NULL return
value.
Signed-off-by: Eduardo Lima (Etrunko) <etrunko redhat com>
govirt/ovirt-proxy.c | 6 ++++++
govirt/ovirt-resource.c | 9 ++++++++-
govirt/ovirt-utils.c | 7 +++++--
3 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index 739bb25..ad00b8c 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -361,6 +361,11 @@ static gboolean get_collection_xml_async_cb(OvirtProxy* proxy,
data = (OvirtProxyGetCollectionAsyncData *)user_data;
root = ovirt_rest_xml_node_from_call(call);
+ if (root == NULL) {
+ g_set_error_literal(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED,
+ _("Failed to parse response from collection"));
+ goto end;
+ }
/* Do the parsing */
g_warn_if_fail(data->parser != NULL);
@@ -370,6 +375,7 @@ static gboolean get_collection_xml_async_cb(OvirtProxy* proxy,
rest_xml_node_unref(root);
+end:
return parsed;
}
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
index 85c55a1..cc670db 100644
--- a/govirt/ovirt-resource.c
+++ b/govirt/ovirt-resource.c
@@ -864,17 +864,24 @@ static gboolean ovirt_resource_refresh_async_cb(OvirtProxy *proxy,
{
OvirtResource *resource;
RestXmlNode *root;
- gboolean refreshed;
+ gboolean refreshed = FALSE;
g_return_val_if_fail(REST_IS_PROXY_CALL(call), FALSE);
g_return_val_if_fail(OVIRT_IS_RESOURCE(user_data), FALSE);
root = ovirt_rest_xml_node_from_call(call);
+ if (root == NULL) {
+ g_set_error_literal(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED,
+ _("Failed to parse response from resource"));
+ goto end;
+ }
+
resource = OVIRT_RESOURCE(user_data);
refreshed = ovirt_resource_init_from_xml(resource, root, error);
rest_xml_node_unref(root);
+end:
return refreshed;
}
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
index dfaf09d..56ce2e1 100644
--- a/govirt/ovirt-utils.c
+++ b/govirt/ovirt-utils.c
@@ -40,11 +40,14 @@ ovirt_rest_xml_node_from_call(RestProxyCall *call)
{
RestXmlParser *parser;
RestXmlNode *node;
+ const char * data = rest_proxy_call_get_payload (call);
+
+ if (data == NULL)
+ return NULL;
parser = rest_xml_parser_new ();
- node = rest_xml_parser_parse_from_data (parser,
- rest_proxy_call_get_payload (call),
+ node = rest_xml_parser_parse_from_data (parser, data,
rest_proxy_call_get_payload_length (call));
g_object_unref(G_OBJECT(parser));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]