dermesser / libsocket

The ultimate socket library for C and C++, supporting TCP, UDP and Unix sockets (DGRAM and STREAM) on Linux, FreeBSD, Solaris. See also my uvco library for a refreshed version!
https://borgac.net/~lbo/doc/libsocket/
Other
797 stars 195 forks source link

Fix possible double close and closing uninitialized fd in create_inet_stream_socket #89

Closed TERESH1 closed 2 months ago

TERESH1 commented 2 months ago
  1. Possible uninitialized data is read from local variable sfd at libinetsocket.c:221. https://github.com/dermesser/libsocket/blob/1a4480a1214cb68cbf28c7f7050cdd76ab85d6f0/C/inet/libinetsocket.c#L155 https://github.com/dermesser/libsocket/blob/1a4480a1214cb68cbf28c7f7050cdd76ab85d6f0/C/inet/libinetsocket.c#L221

  2. Handler sfd is passed to a function at libinetsocket.c:221 by calling function close after the handler may already be closed at libinetsocket.c:209. https://github.com/dermesser/libsocket/blob/1a4480a1214cb68cbf28c7f7050cdd76ab85d6f0/C/inet/libinetsocket.c#L194-L221

Setting fd to -1 would avoid the risk of closing a socket that another thread had just opened

Found with Svace