From fe252a1410f226718872cb54a1919850c1450c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 10 Feb 2021 16:15:49 +0100 Subject: [PATCH 1/3] module/script: fix typo in memcmp() Patch by Jan Beich --- modules/script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/script.c b/modules/script.c index 766ea96..7e07365 100644 --- a/modules/script.c +++ b/modules/script.c @@ -148,7 +148,7 @@ process_line(struct module *mod, const char *line, size_t len) } else if ((type_len > 6 && memcmp(type, "range:", 6) == 0) || - (type_len > 9 && memcmp(type, "realtime:", 9 == 0))) + (type_len > 9 && memcmp(type, "realtime:", 9) == 0)) { const char *_start = type + 6; const char *split = memchr(_start, '-', type_len - 6); From afe22813f32a945b0df741fe5538d26e92bc343a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 14 Jan 2021 11:20:02 +0100 Subject: [PATCH 2/3] =?UTF-8?q?changelog:=20add=20a=20new=20=E2=80=98unrel?= =?UTF-8?q?eased=E2=80=99=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d7c2d..94cdf62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,22 @@ # Changelog +* [Unreleased](#Unreleased) * [1.6.1](#1-6-1) * [1.6.0](#1-6-0) * [1.5.0](#1-5-0) +## Unreleased + +### Added +### Changed +### Deprecated +### Removed +### Fixed +### Security +### Contributors + + ## 1.6.1 ### Changed From 0855e5ff6371d6954c8d6b0dbcf18ea0252e24b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 11 Feb 2021 19:02:14 +0100 Subject: [PATCH 3/3] =?UTF-8?q?yml:=20don=E2=80=99t=20crash=20when=20(tryi?= =?UTF-8?q?ng=20to)=20merge=20anchors=20that=20aren=E2=80=99t=20dictionari?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Up until now, we only asserted the value being merged in was a dictionary. Now we do a proper check and return a real error message instead. Closes #32 --- CHANGELOG.md | 5 +++++ yml.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94cdf62..e5a1acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ ### Deprecated ### Removed ### Fixed + +* Crash when merging non-dictionary anchors in the YAML configuration + (https://codeberg.org/dnkl/yambar/issues/32). + + ### Security ### Contributors diff --git a/yml.c b/yml.c index bdf474a..52370ef 100644 --- a/yml.c +++ b/yml.c @@ -177,13 +177,14 @@ add_anchor(struct yml_node *root, const char *anchor, root->root.anchor_count++; } -static void -post_process(struct yml_node *node) +static bool +post_process(struct yml_node *node, char **error) { switch (node->type) { case ROOT: if (node->root.root != NULL) - post_process(node->root.root); + if (!post_process(node->root.root, error)) + return false; break; case SCALAR: @@ -192,13 +193,17 @@ post_process(struct yml_node *node) case LIST: tll_foreach(node->list.values, it) - post_process(it->item); + if (!post_process(it->item, error)) + return false; break; case DICT: tll_foreach(node->dict.pairs, it) { - post_process(it->item.key); - post_process(it->item.value); + if (!post_process(it->item.key, error) || + !post_process(it->item.value, error)) + { + return false; + } } tll_foreach(node->dict.pairs, it) { @@ -214,7 +219,17 @@ post_process(struct yml_node *node) * e.g. <<: [*foo, *bar] */ tll_foreach(it->item.value->list.values, v_it) { - assert(v_it->item->type == DICT); + if (v_it->item->type != DICT) { + int cnt = snprintf( + NULL, 0, "%zu:%zu: cannot merge non-dictionary anchor", + v_it->item->line, v_it->item->column); + *error = malloc(cnt + 1); + snprintf( + *error, cnt + 1, "%zu:%zu: cannot merge non-dictionary anchor", + v_it->item->line, v_it->item->column); + return false; + } + tll_foreach(v_it->item->dict.pairs, vv_it) { struct dict_pair p = { .key = vv_it->item.key, @@ -240,7 +255,17 @@ post_process(struct yml_node *node) * Merge value is a dictionary only * e.g. <<: *foo */ - assert(it->item.value->type == DICT); + if (it->item.value->type != DICT) { + int cnt = snprintf( + NULL, 0, "%zu:%zu: cannot merge non-dictionary anchor", + it->item.value->line, it->item.value->column); + *error = malloc(cnt + 1); + snprintf( + *error, cnt + 1, "%zu:%zu: cannot merge non-dictionary anchor", + it->item.value->line, it->item.value->column); + return false; + } + tll_foreach(it->item.value->dict.pairs, v_it) { struct dict_pair p = { .key = v_it->item.key, @@ -269,6 +294,8 @@ post_process(struct yml_node *node) } break; } + + return true; } static const char * @@ -526,7 +553,10 @@ yml_load(FILE *yml, char **error) yaml_parser_delete(&yaml); - post_process(root); + if (!post_process(root, error)) { + yml_destroy(root); + return NULL; + } return root; err: