summaryrefslogtreecommitdiff
path: root/plugins/yaml/reader.c
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/reader.c
parent4b54747c0ee3736591b3fb38b156837b0958b1cc (diff)
Improved the stability of the Yaml parser.
Diffstat (limited to 'plugins/yaml/reader.c')
-rw-r--r--plugins/yaml/reader.c23
1 files changed, 14 insertions, 9 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;
}