yml: don’t overwrite errors from yml_parser_parse()

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.
This commit is contained in:
Daniel Eklöf 2020-09-24 13:27:48 +02:00
parent 57e755477c
commit eceee99fb0
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 8 additions and 1 deletions

View file

@ -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

4
yml.c
View file

@ -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;