From 11662ed5b5c53be400f4de08ee715e461d491ec1 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 28 Oct 2019 21:14:17 +0100 Subject: [PATCH] Don't call terminate_connection() from meshlink_blacklist(). If meshlink_blacklist() is called from a callback function, this can result in a use-after-free bug. Instead, shut down the socket, so the event loop will take care of it. --- src/meshlink.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 98e02f7d..dd571190 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -2831,10 +2831,12 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name); - //Immediately terminate any connections we have with the blacklisted node + /* Immediately shut down any connections we have with the blacklisted node. + * We can't call terminate_connection(), because we might be called from a callback function. + */ for list_each(connection_t, c, mesh->connections) { if(c->node == n) { - terminate_connection(mesh, c, c->status.active); + shutdown(c->socket, SHUT_RDWR); } } @@ -2846,10 +2848,6 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { n->mtuprobes = 0; n->status.udp_confirmed = false; - if(n->status.reachable) { - update_node_status(mesh, n); - } - pthread_mutex_unlock(&mesh->mutex); } -- 2.39.2