-
Notifications
You must be signed in to change notification settings - Fork 913
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
peer_control: Fix a use-after-free bug. #1237
peer_control: Fix a use-after-free bug. #1237
Conversation
I don't see where we free channel here? |
We are freeing |
Excellent find, we are indeed leaving a dangling pointer in lightning/lightningd/peer_control.c Lines 440 to 443 in 234d67d
That would avoid duplicating the error. |
72d4382
to
8d69f94
Compare
Allocated off |
8d69f94
to
72d4382
Compare
Allocating off |
Here's the clue from that failure: Basically, we call Christian's advice of using tmpctx here is correct: one subtle advantage of tal() is that you can have two paths, one of which uses a temporary and one which doesn't, and simply free the parent and not worry about distinguishing the two. In this case, tmpctx is the correct parent. |
This bug is a classic case of being lazy: 1. peer_accept_channel() allocated its return off the input message, rather than taking an explicit allocation context. This concealed the lifetime nature of the return. 2. The context for sanitize_error was the error itself, rather than the more obvious tmpctx (connect_failed does not take). The global tmpctx removes the "efficiency" excuse for grabbing a random object to use as context, and is also nice and explicit.
How's that, @ZmnSCPxj ? |
Looks OK. |
Oh, very nice find! |
Possibly related to #1235 and #1236, but not confirmed to fix that.