Skip to content

Commit

Permalink
libvncserver: don't give invalid fds to FD_* macros
Browse files Browse the repository at this point in the history
re #655
  • Loading branch information
bk138 committed Mar 5, 2025
1 parent b17c592 commit eae4f70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libvncserver/rfbserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,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 @@ -672,6 +672,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 @@ -772,6 +776,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 @@ -888,6 +896,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 eae4f70

Please sign in to comment.