From c71e5e7bbdbbf8b3124ee60313589decde1e8921 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 3 Dec 2022 13:12:29 +0300 Subject: [PATCH] Fix possible use-after-free during pings --- src/messenger.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/messenger.cpp b/src/messenger.cpp index 73ec23cc..50b557b1 100644 --- a/src/messenger.cpp +++ b/src/messenger.cpp @@ -80,12 +80,20 @@ void osd_messenger_t::init() }; op->callback = [this, cl](osd_op_t *op) { + auto cl_it = clients.find(op->peer_fd); + if (cl_it == clients.end() || cl_it->second != cl) + { + // client is already dropped + delete op; + return; + } int fail_fd = (op->reply.hdr.retval != 0 ? op->peer_fd : -1); + auto fail_osd_num = cl->osd_num; cl->ping_time_remaining = 0; delete op; if (fail_fd >= 0) { - fprintf(stderr, "Ping failed for OSD %lu (client %d), disconnecting peer\n", cl->osd_num, cl->peer_fd); + fprintf(stderr, "Ping failed for OSD %lu (client %d), disconnecting peer\n", fail_osd_num, fail_fd); stop_client(fail_fd, true); } };