Skip to content

Commit

Permalink
Merge branch 'master' into multicastvnc
Browse files Browse the repository at this point in the history
  • Loading branch information
bk138 committed Mar 5, 2025
2 parents caddfeb + eae4f70 commit 6194ae4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/common/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ rfbBool sock_wait_for_connected(int socket, unsigned int timeout_seconds)
timeout.tv_sec=timeout_seconds;
timeout.tv_usec=0;

if(socket == RFB_INVALID_SOCKET) {
errno = EBADF;
return FALSE;
}

FD_ZERO(&writefds);
FD_SET(socket, &writefds);
FD_ZERO(&exceptfds);
Expand Down
8 changes: 4 additions & 4 deletions src/libvncclient/listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ listenForIncomingConnections(rfbClient* client)
r = select(rfbMax(listenSocket, listen6Socket)+1, &fds, NULL, NULL, NULL);

if (r > 0) {
if (FD_ISSET(listenSocket, &fds))
if (listenSocket != RFB_INVALID_SOCKET && FD_ISSET(listenSocket, &fds))
client->sock = AcceptTcpConnection(client->listenSock);
else if (FD_ISSET(listen6Socket, &fds))
else if (listen6Socket != RFB_INVALID_SOCKET && FD_ISSET(listen6Socket, &fds))
client->sock = AcceptTcpConnection(client->listen6Sock);

if (client->sock == RFB_INVALID_SOCKET)
Expand Down Expand Up @@ -201,9 +201,9 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout)

if (r > 0)
{
if (FD_ISSET(client->listenSock, &fds))
if (client->listenSock != RFB_INVALID_SOCKET && FD_ISSET(client->listenSock, &fds))
client->sock = AcceptTcpConnection(client->listenSock);
else if (FD_ISSET(client->listen6Sock, &fds))
else if (client->listen6Sock != RFB_INVALID_SOCKET && FD_ISSET(client->listen6Sock, &fds))
client->sock = AcceptTcpConnection(client->listen6Sock);

if (client->sock == RFB_INVALID_SOCKET)
Expand Down
11 changes: 11 additions & 0 deletions src/libvncclient/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n)
errno == ENOENT ||
#endif
errno == EAGAIN) {
if(client->sock == RFB_INVALID_SOCKET) {
errno = EBADF;
rfbClientErr("socket invalid\n");
return FALSE;
}

FD_ZERO(&fds);
FD_SET(client->sock,&fds);

Expand Down Expand Up @@ -975,6 +981,11 @@ int WaitForMessage(rfbClient* client,unsigned int usecs)
timeout.tv_sec=(usecs/1000000);
timeout.tv_usec=(usecs%1000000);

if(client->sock == RFB_INVALID_SOCKET) {
errno = EBADF;
return -1;
}

FD_ZERO(&fds);
FD_SET(client->sock,&fds);
maxfd = client->sock;
Expand Down
5 changes: 5 additions & 0 deletions src/libvncclient/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ static int sock_read_ready(SSL *ssl, uint32_t ms)

FD_ZERO(&fds);

if(SSL_get_fd(ssl) == RFB_INVALID_SOCKET) {
errno = EBADF;
return -1;
}

FD_SET(SSL_get_fd(ssl), &fds);

tv.tv_sec = ms / 1000;
Expand Down
4 changes: 4 additions & 0 deletions src/libvncserver/rfbserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,10 @@ rfbBool rfbSendFileTransferChunk(rfbClientPtr cl)
/* If not sending, or no file open... Return as if we sent something! */
if ((cl->fileTransfer.fd!=-1) && (cl->fileTransfer.sending==1))
{
if(cl->sock == RFB_INVALID_SOCKET) {
errno = EBADF;
return FALSE;
}
FD_ZERO(&wfds);
FD_SET(cl->sock, &wfds);

Expand Down
12 changes: 12 additions & 0 deletions src/libvncserver/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ rfbReadExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
struct timeval tv;

while (len > 0) {
if(sock == RFB_INVALID_SOCKET) {
errno = EBADF;
return -1;
}
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
if (cl->wsctx) {
n = webSocketsDecode(cl, buf, len);
Expand Down Expand Up @@ -896,6 +900,10 @@ rfbPeekExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
struct timeval tv;

while (len > 0) {
if(sock == RFB_INVALID_SOCKET) {
errno = EBADF;
return -1;
}
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
if (cl->sslctx)
n = rfbssl_peek(cl, buf, len);
Expand Down Expand Up @@ -1012,6 +1020,10 @@ rfbWriteExact(rfbClientPtr cl,

LOCK(cl->outputMutex);
while (len > 0) {
if(sock == RFB_INVALID_SOCKET) {
errno = EBADF;
return -1;
}
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
if (cl->sslctx)
n = rfbssl_write(cl, buf, len);
Expand Down

0 comments on commit 6194ae4

Please sign in to comment.