From eceee99fb0aaddaa3842d07c41a8a9b9ff947af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Sep 2020 13:27:48 +0200 Subject: [PATCH] =?UTF-8?q?yml:=20don=E2=80=99t=20overwrite=20errors=20fro?= =?UTF-8?q?m=20yml=5Fparser=5Fparse()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we detect an error in yml_parser_parse(), we handle that specifically, and then jump to the generic error handler. The generic error handler overwrites the previously formatted error before cleaning up and returning. This meant that a) the actual error message was lost, and replaced with a generic “unknown error”, and b) the dynamically allocated error string buffer was leaked. --- CHANGELOG.md | 5 +++++ yml.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea8f2c6..bdd3c67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ ### Deprecated ### Removed ### Fixed + +* YAML parsing error messages being replaced with a generic “unknown error”. +* Memory leak when a YAML parsing error was encoutered. + + ### Security ### Contributors diff --git a/yml.c b/yml.c index 73e5083..40ece40 100644 --- a/yml.c +++ b/yml.c @@ -383,7 +383,7 @@ yml_load(FILE *yml, char **error) yaml.context != NULL ? yaml.context : ""); } - goto err; + goto err_no_error_formatting; } switch (event.type) { @@ -550,6 +550,8 @@ err: yaml.mark.line + 1, yaml.mark.column); } +err_no_error_formatting: + yml_destroy(root); yaml_parser_delete(&yaml); return NULL;