[gnome-software: 15/20] fedora-pkgdb-collections: Fix handling of NULL root node
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 15/20] fedora-pkgdb-collections: Fix handling of NULL root node
- Date: Thu, 17 Mar 2022 10:27:11 +0000 (UTC)
commit 5a25c68e80e07d40e0c8828f5e2ebcf0a432499a
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Mar 11 12:26:07 2022 +0000
fedora-pkgdb-collections: Fix handling of NULL root node
If the JSON file exists but is empty, parsing will succeed, but
`json_parser_get_root()` will return `NULL`.
Handle that case to avoid a critical warning from
`json_node_get_object()`. Also add some type checking of the root node.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1670
.../fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 18ee79d4d..965bdc595 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -464,7 +464,8 @@ load_json (GsPluginFedoraPkgdbCollections *self,
GError **error)
{
JsonArray *collections;
- JsonObject *root;
+ JsonNode *root_node;
+ JsonObject *root = NULL;
g_autoptr(JsonParser) parser = NULL;
g_autoptr(GPtrArray) new_distros = NULL;
@@ -474,7 +475,9 @@ load_json (GsPluginFedoraPkgdbCollections *self,
if (!json_parser_load_from_mapped_file (parser, self->cachefn, error))
return NULL;
- root = json_node_get_object (json_parser_get_root (parser));
+ root_node = json_parser_get_root (parser);
+ if (root_node != NULL && JSON_NODE_HOLDS_OBJECT (root_node))
+ root = json_node_get_object (root_node);
if (root == NULL) {
g_set_error (error,
GS_PLUGIN_ERROR,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]