From e90f005a1066075f0d79531ede763fadb51f61ee Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 12 Jul 2021 06:12:05 +0100 Subject: [PATCH] vhost: listen: protect listen port transfer between ...vhosts from vh destroy on zero refcount https://github.com/warmcat/libwebsockets/issues/2343 --- lib/core-net/vhost.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 0ba451cdb..852155bd6 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -1272,8 +1272,23 @@ lws_vhost_destroy1(struct lws_vhost *vh) if (v->lserv_wsi) { /* req cx + vh lock */ + /* + * If the vhost sees it's being destroyed and + * in the unbind the number of wsis bound to + * it falls to zero, it will destroy the + * vhost opportunistically before we can + * complete the transfer. Add a fake wsi + * bind temporarily to disallow this... + */ + v->count_bound_wsi++; __lws_vhost_unbind_wsi(vh->lserv_wsi); lws_vhost_bind_wsi(v, v->lserv_wsi); + + /* + * ... remove the fake wsi bind + */ + v->count_bound_wsi--; + vh->lserv_wsi = NULL; }