Skip to content

channeld: fix dev_disconnect doublefree crash. #1756

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

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions channeld/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ static void enqueue_peer_msg(struct peer *peer, const u8 *msg TAKES)
/* Should not return */
abort();
case DEV_DISCONNECT_DROPPKT:
tal_free(msg);
if (taken(msg))
tal_free(msg);
/* Fail next time we try to do something. */
dev_sabotage_fd(PEER_FD);
return;
Expand Down Expand Up @@ -1848,7 +1849,7 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last

static bool channeld_send_reply(struct crypto_state *cs UNUSED,
int peer_fd UNUSED,
const u8 *msg UNUSED,
const u8 *msg,
struct peer *peer)
{
enqueue_peer_msg(peer, msg);
Expand Down Expand Up @@ -2670,15 +2671,15 @@ int main(int argc, char *argv[])
}

if (FD_ISSET(MASTER_FD, &rfds)) {
msg = wire_sync_read(peer, MASTER_FD);
msg = wire_sync_read(tmpctx, MASTER_FD);

if (!msg)
status_failed(STATUS_FAIL_MASTER_IO,
"Can't read command: %s",
strerror(errno));
req_in(peer, msg);
} else if (FD_ISSET(GOSSIP_FD, &rfds)) {
msg = wire_sync_read(peer, GOSSIP_FD);
msg = wire_sync_read(tmpctx, GOSSIP_FD);
/* Gossipd hangs up on us to kill us when a new
* connection comes in. */
if (!msg)
Expand All @@ -2689,11 +2690,11 @@ int main(int argc, char *argv[])
} else if (FD_ISSET(PEER_FD, &rfds)) {
/* This could take forever, but who cares? */
msg = channeld_read_peer_msg(peer);
if (msg)
if (msg) {
peer_in(peer, msg);
} else
msg = NULL;
tal_free(msg);
tal_free(msg);
}
}
}

/* We only exit when shutdown is complete. */
Expand Down