Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors from the yaml parser #41

Closed
wants to merge 2 commits into from
Closed

Handle errors from the yaml parser #41

wants to merge 2 commits into from

Conversation

neilmayhew
Copy link
Contributor

@neilmayhew neilmayhew commented May 10, 2016

This is a more complete treatment of the problem described in #35


This change is Reviewable

@ximion
Copy link
Owner

ximion commented May 10, 2016

This could be the reason why this change wasn't noticed so far: The XML parser ignored garbage after the root node was closed, and for the YAML parser we simply ignored all errors in the format... Bad thing!

@@ -172,7 +178,7 @@ dep11_yaml_process_layer (yaml_parser_t *parser, GNode *data)
last_scalar = last_leaf;
if (in_sequence)
last_leaf = g_node_append (last_leaf, g_node_new (g_strdup ("-")));
dep11_yaml_process_layer (parser, last_leaf);
dep11_yaml_process_layer (parser, last_leaf, error);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to check if error is NULL after that statement (and then return from the function), because otherwise in the (unlikely) event that the recursion emits multiple errors, we will get a crash when an attempt is made to set an error on a non-NULL GError object.

@ximion
Copy link
Owner

ximion commented May 10, 2016

I added a few remarks to the patch, you basically would need to exit as early as possible to prevent GError being set twice.

@neilmayhew
Copy link
Contributor Author

neilmayhew commented May 10, 2016

I think there are some pre-existing places where memory will be leaked due to the event not being deleted. See the breaks on lines 1861 & 1879 (old numbers) or 1876 & 1894 (new numbers).

g_assert_null (cpt);

if (error != NULL) {
g_assert_true (g_str_has_prefix (error->message, "Invalid DEP-11 file found: YAML parsing error"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be considered too brittle, as it's closely tied to the exact format of the error messages generated.

@neilmayhew neilmayhew mentioned this pull request May 10, 2016
@ximion ximion closed this in b62b463 May 11, 2016
ximion pushed a commit that referenced this pull request May 11, 2016
Based on an initial patch by Neil Mayhew, with modifications from
Matthias Klumpp.

Resolves #41

Signed-off-by: Matthias Klumpp <matthias@tenstral.net>
@ximion
Copy link
Owner

ximion commented May 11, 2016

I committed your patch with some modifications to make the GError handling more robust and GLib-ish, and make the parse function return NULL correctly in case of an error.
Also fixed a few GError related minor memory leaks in the testsuite.

Thank you for your patch and general help in debugging this! (Also, it's always awesome to have people provide testsuite testcases with the first patch!)

@ximion
Copy link
Owner

ximion commented May 11, 2016

Oh, and btw: I will do a new AppStream release tomorrow, which will include these changes.

@neilmayhew
Copy link
Contributor Author

Thanks for accepting my change. I've not done much programming in the glib environment before, so I'm not surprised it needed some improvements.

It's been a fun and interesting experience working on this, but I hope that everything is fixed now (and SRUs made) so I can get back to my other projects!

@ximion
Copy link
Owner

ximion commented May 11, 2016

The SRUs are not in my hands - that's up to Ubuntus stable release maintainers. The AppStream changes are in the queue for proposed-updates, and the appstream-glib changes are pending to be uploaded.
Debian, which is the thing I have more influence on, is ready ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants