You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brief:
If the lws_create_adopt_udp() function fails to bind a socket and returns NULL, then subsequent call of the lws_vhost_destroy() leads to crash
Details:
When the lws_create_adopt_udp() starts, it creates a wsi object and saves it in the vhost->vh_awaiting_socket_owner list (see the __lws_adopt_descriptor_vhost1() function). Then if the lws_create_adopt_udp() fails to bind a socket, it doen't destroy the wsi object, but leaves it in the vhost->vh_awaiting_socket_owner list.
When the lws_vhost_destroy() is called, it starts closing all its wsi objects in the __lws_vhost_destroy_pt_wsi_dieback_start() function. But when the last wsi is destroyed, the whole vhost is also destroyed, look at the call chain: __lws_vhost_destroy_pt_wsi_dieback_start() -> lws_close_free_wsi() -> __lws_close_free_wsi() -> __lws_close_free_wsi_final() -> __lws_free_wsi() -> __lws_vhost_unbind_wsi() -> __lws_vhost_destroy2(). After return from this chain the lws_vhost_destroy() function accesses to the already destroyedvh object and calls __lws_vhost_destroy2() again on it
How to reproduce
Here is the minimal code snippet to reproduce the problem. To trigger the error in the lws_create_adopt_udp() we firstly bind socket to the port 55505 and then call lws_create_adopt_udp() with the same port number. Then subsequent call of the lws_vhost_destroy(vhost); leads to crash.
Also if we comment out the line lws_vhost_destroy(vhost); // <- here should be a crash, we will get memory leaks (see the memory sanitizer output). To build the snippet, run:
Libwebsockets version:
4.3.2
OS:
Linux
Brief:
If the
lws_create_adopt_udp()
function fails to bind a socket and returns NULL, then subsequent call of thelws_vhost_destroy()
leads to crashDetails:
lws_create_adopt_udp()
starts, it creates awsi
object and saves it in thevhost->vh_awaiting_socket_owner
list (see the__lws_adopt_descriptor_vhost1()
function). Then if thelws_create_adopt_udp()
fails to bind a socket, it doen't destroy thewsi
object, but leaves it in thevhost->vh_awaiting_socket_owner
list.lws_vhost_destroy()
is called, it starts closing all itswsi
objects in the__lws_vhost_destroy_pt_wsi_dieback_start()
function. But when the lastwsi
is destroyed, the wholevhost
is also destroyed, look at the call chain:__lws_vhost_destroy_pt_wsi_dieback_start() -> lws_close_free_wsi() -> __lws_close_free_wsi() -> __lws_close_free_wsi_final() -> __lws_free_wsi() -> __lws_vhost_unbind_wsi() -> __lws_vhost_destroy2()
. After return from this chain thelws_vhost_destroy()
function accesses to the already destroyedvh
object and calls__lws_vhost_destroy2()
again on itHow to reproduce
Here is the minimal code snippet to reproduce the problem. To trigger the error in the
lws_create_adopt_udp()
we firstly bind socket to the port 55505 and then calllws_create_adopt_udp()
with the same port number. Then subsequent call of thelws_vhost_destroy(vhost);
leads to crash.Also if we comment out the line
lws_vhost_destroy(vhost); // <- here should be a crash
, we will get memory leaks (see the memory sanitizer output). To build the snippet, run:where the
./lws/
is a folder withlibwebsockets
, and the./tls/
is a folder with tls backend (in my case it'smbedtls
Minimal snippet
The text was updated successfully, but these errors were encountered: