Skip to content

Commit

Permalink
libvncserver: mitigate FORTIFY crash in listenerRun()
Browse files Browse the repository at this point in the history
With the previous commit acac779
the select() call now times out, opening up for a race condition
where rfbShutdownSockets() would set the listening sockets to -1,
the select would time out and the FD_ISSET() call encounter a -1
socket.

This is not 100% threadsafe but better than before.
  • Loading branch information
bk138 committed Aug 26, 2024
1 parent acac779 commit 06cff31
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,9 @@ listenerRun(void *data)

/* If there is something on the listening sockets, handle new connections */
len = sizeof (peer);
if (FD_ISSET(screen->listenSock, &listen_fds))
if (screen->listenSock != RFB_INVALID_SOCKET && FD_ISSET(screen->listenSock, &listen_fds))
client_fd = accept(screen->listenSock, (struct sockaddr*)&peer, &len);
else if (FD_ISSET(screen->listen6Sock, &listen_fds))
else if (screen->listen6Sock != RFB_INVALID_SOCKET && FD_ISSET(screen->listen6Sock, &listen_fds))
client_fd = accept(screen->listen6Sock, (struct sockaddr*)&peer, &len);

if(client_fd >= 0)
Expand Down

0 comments on commit 06cff31

Please sign in to comment.