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

aug_rm: fix segfault when deleting a tree and one of its ancestors #320

Merged
merged 1 commit into from
Nov 26, 2015

Conversation

lutter
Copy link
Member

@lutter lutter commented Nov 24, 2015

In a tree like /files/1/2, when we execute 'rm /files//*', the path
expression matches /files/1 and /files/1/2. When tree_rm goes to delete
these two nodes, it first deletes (frees) /files/1 and all its
descendents. By the time we try to delete /files/1/2, the pointer we have
to that is no longer valid and we end up causing a double-free.

With this change, we make sure we only delete a node if none of its
ancestors is being deleted beforehand in the same operation - deleting a
node, and one of its ancestors afterwards is fine as the pointer to the
ancestor is still valid.

Fixes #319

Special shoutout to Geoff Williams for finding, diagnosing and filing a
great bug report about this.

@GeoffWilliams
Copy link
Contributor

Wow that was quick, thanks @lutter !

I was originally drafting the report as a request for help fixing this and in the process identified the root cause of the bug. I've tested the PR and can confirm this fixes the problem I was having.

Thanks!
Geoff

In a tree like /files/1/2, when we execute 'rm /files//*', the path
expression matches /files/1 and /files/1/2. When tree_rm goes to delete
these two nodes, it first deletes (frees) /files/1 and all its
descendents. By the time we try to delete /files/1/2, the pointer we have
to that is no longer valid and we end up causing a double-free.

With this change, we make sure we only delete a node if none of its
ancestors is being deleted beforehand in the same operation - deleting a
node, and one of its ancestors afterwards is fine as the pointer to the
ancestor is still valid.

Fixes hercules-team#319

Special shoutout to Geoff Williams for finding, diagnosing and filing a
great bug report about this.
@lutter lutter merged commit e80ae69 into hercules-team:master Nov 26, 2015
@lutter lutter deleted the bug/319 branch November 26, 2015 00:15
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.

2 participants