summaryrefslogtreecommitdiff
path: root/plugins/yaml
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-01-05 22:45:38 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-01-05 22:45:38 (GMT)
commit9ce85bcdf8da124ad9538875f945ab5c4bb09e1e (patch)
tree1bef85d7d9f2fbadf25540b43c2f138645a05265 /plugins/yaml
parent4b54747c0ee3736591b3fb38b156837b0958b1cc (diff)
Improved the stability of the Yaml parser.
Diffstat (limited to 'plugins/yaml')
-rw-r--r--plugins/yaml/reader.c23
-rw-r--r--plugins/yaml/tree.c17
2 files changed, 29 insertions, 11 deletions
diff --git a/plugins/yaml/reader.c b/plugins/yaml/reader.c
index c8852bb..54273c1 100644
--- a/plugins/yaml/reader.c
+++ b/plugins/yaml/reader.c
@@ -197,20 +197,25 @@ GYamlReader *g_yaml_reader_new_from_content(const char *content, size_t length)
*iter != '\0';
iter = ++saved, saved = strchr(iter, '\n'), number++)
{
- *saved = '\0';
+ if (saved != NULL)
+ *saved = '\0';
- if (*iter == '\0')
- continue;
+ if (*iter != '\0')
+ {
+ line = g_yaml_line_new(iter, number);
- line = g_yaml_line_new(iter, number);
+ if (line == NULL)
+ goto format_error;
- if (line == NULL)
- goto format_error;
+ result->lines = realloc(result->lines, ++result->count * sizeof(GYamlLine *));
- result->lines = realloc(result->lines, ++result->count * sizeof(GYamlLine *));
+ g_object_ref_sink(G_OBJECT(line));
+ result->lines[result->count - 1] = line;
- g_object_ref_sink(G_OBJECT(line));
- result->lines[result->count - 1] = line;
+ }
+
+ if (saved == NULL)
+ break;
}
diff --git a/plugins/yaml/tree.c b/plugins/yaml/tree.c
index 5db82ec..4487f9d 100644
--- a/plugins/yaml/tree.c
+++ b/plugins/yaml/tree.c
@@ -270,7 +270,11 @@ static bool g_yaml_tree_build_node(GYamlCollection *collec, GYamlLine **lines, s
/* Début d'un sous-ensemble */
else if (indent > expected)
{
- assert(last != NULL);
+ if (last == NULL)
+ {
+ result = false;
+ goto done;
+ }
sub = g_yaml_collection_new(is_item);
g_yaml_pair_set_collection(G_YAML_PAIR(last), sub);
@@ -319,6 +323,13 @@ static bool g_yaml_tree_build_node(GYamlCollection *collec, GYamlLine **lines, s
}
last = G_YAML_NODE(g_yaml_pair_new(line));
+
+ if (last == NULL)
+ {
+ result = false;
+ goto done;
+ }
+
g_yaml_collection_add_node(collec, last);
(*cur)++;
@@ -353,7 +364,9 @@ GYamlNode *g_yaml_tree_get_root(const GYamlTree *tree)
GYamlNode *result; /* Liste à retourner */
result = tree->root;
- g_object_ref(G_OBJECT(result));
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
return result;