-
Notifications
You must be signed in to change notification settings - Fork 199
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
Double free with AUG_ENABLE_SPAN in free_tree_node #397
Comments
I just tried this on my machine (Fedora 23, augeas 1.5.0) and it does not produce an error. Running it under valgrind or with It could be that some config file you have triggers something. Can you try if running |
Cool! I'll try on a fresh VM with debugging enabled for the few dependencies and see if I can reproduce. |
I may have been compiling against a newer libz/libxml2 than existed within the system paths. A clean Ubuntu16.04 works fine. Sorry for the noise 💃 |
Ok, it seems this is not related to my build, but rather
Multiple |
With a few added trace statements and ASAN's output:
To trigger within diff --git a/src/augtool.c b/src/augtool.c
index 1aa58ec..3521fe8 100644
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -720,6 +720,7 @@ int main(int argc, char **argv) {
if (history_file != NULL)
write_history(history_file);
+ aug_close(aug);
return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} |
Wow .. that's awesome detective work ! Thanks so much for the great bug report. I believe the culprit is the aliasing of pointers that happens in visit_enter in get.c I think I have a fix, but still need to clean it up a little. |
…are used When spans are enabled, we used to store a a pointer to the same span both in a frame and in the current state for L_SUBTREE lenses, which meant that two different tree nodes might have pointers to the same span. That is counter to the assumptions made about tree nodes, in that they need to own the spans attached to them, resulting in a use-after-free. It would also record incorrect span information in one of the tree nodes. We now allocate a new span when we store one in the frame - that way we are guaranteed that there is no aliasing. With L_MAYBE lenses, visit_enter allocated a new span in state, thus possibly leaking the one that might be there already. We now store that span in the frame that we push for L_MAYBE, avoiding that leak. Finally, we popped frames in visit_exit without doing anything with them. We now also free any associated span to make sure we do not leak that information. Fixes hercules-team#397
Woot! Thanks for jumping on this so quickly @lutter. :) |
Any interest in adding the |
@theopolis I just added a commit to that effect; it's not strictly necessary, but I agree getting error reports over mishandled memory earlier would be good. |
I tried a tiny test:
Cool!
Now change:
And it will crash with the double free. Perhaps I'm using the C API incorrectly?
The text was updated successfully, but these errors were encountered: