Skip to content

Commit 6194ae4

Browse files
committed
Merge branch 'master' into multicastvnc
2 parents caddfeb + eae4f70 commit 6194ae4

6 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/common/sockets.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ rfbBool sock_wait_for_connected(int socket, unsigned int timeout_seconds)
6060
timeout.tv_sec=timeout_seconds;
6161
timeout.tv_usec=0;
6262

63+
if(socket == RFB_INVALID_SOCKET) {
64+
errno = EBADF;
65+
return FALSE;
66+
}
67+
6368
FD_ZERO(&writefds);
6469
FD_SET(socket, &writefds);
6570
FD_ZERO(&exceptfds);

src/libvncclient/listen.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ listenForIncomingConnections(rfbClient* client)
102102
r = select(rfbMax(listenSocket, listen6Socket)+1, &fds, NULL, NULL, NULL);
103103

104104
if (r > 0) {
105-
if (FD_ISSET(listenSocket, &fds))
105+
if (listenSocket != RFB_INVALID_SOCKET && FD_ISSET(listenSocket, &fds))
106106
client->sock = AcceptTcpConnection(client->listenSock);
107-
else if (FD_ISSET(listen6Socket, &fds))
107+
else if (listen6Socket != RFB_INVALID_SOCKET && FD_ISSET(listen6Socket, &fds))
108108
client->sock = AcceptTcpConnection(client->listen6Sock);
109109

110110
if (client->sock == RFB_INVALID_SOCKET)
@@ -201,9 +201,9 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout)
201201

202202
if (r > 0)
203203
{
204-
if (FD_ISSET(client->listenSock, &fds))
204+
if (client->listenSock != RFB_INVALID_SOCKET && FD_ISSET(client->listenSock, &fds))
205205
client->sock = AcceptTcpConnection(client->listenSock);
206-
else if (FD_ISSET(client->listen6Sock, &fds))
206+
else if (client->listen6Sock != RFB_INVALID_SOCKET && FD_ISSET(client->listen6Sock, &fds))
207207
client->sock = AcceptTcpConnection(client->listen6Sock);
208208

209209
if (client->sock == RFB_INVALID_SOCKET)

src/libvncclient/sockets.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n)
407407
errno == ENOENT ||
408408
#endif
409409
errno == EAGAIN) {
410+
if(client->sock == RFB_INVALID_SOCKET) {
411+
errno = EBADF;
412+
rfbClientErr("socket invalid\n");
413+
return FALSE;
414+
}
415+
410416
FD_ZERO(&fds);
411417
FD_SET(client->sock,&fds);
412418

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

984+
if(client->sock == RFB_INVALID_SOCKET) {
985+
errno = EBADF;
986+
return -1;
987+
}
988+
978989
FD_ZERO(&fds);
979990
FD_SET(client->sock,&fds);
980991
maxfd = client->sock;

src/libvncclient/tls_openssl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ static int sock_read_ready(SSL *ssl, uint32_t ms)
167167

168168
FD_ZERO(&fds);
169169

170+
if(SSL_get_fd(ssl) == RFB_INVALID_SOCKET) {
171+
errno = EBADF;
172+
return -1;
173+
}
174+
170175
FD_SET(SSL_get_fd(ssl), &fds);
171176

172177
tv.tv_sec = ms / 1000;

src/libvncserver/rfbserver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,10 @@ rfbBool rfbSendFileTransferChunk(rfbClientPtr cl)
16841684
/* If not sending, or no file open... Return as if we sent something! */
16851685
if ((cl->fileTransfer.fd!=-1) && (cl->fileTransfer.sending==1))
16861686
{
1687+
if(cl->sock == RFB_INVALID_SOCKET) {
1688+
errno = EBADF;
1689+
return FALSE;
1690+
}
16871691
FD_ZERO(&wfds);
16881692
FD_SET(cl->sock, &wfds);
16891693

src/libvncserver/sockets.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ rfbReadExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
796796
struct timeval tv;
797797

798798
while (len > 0) {
799+
if(sock == RFB_INVALID_SOCKET) {
800+
errno = EBADF;
801+
return -1;
802+
}
799803
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
800804
if (cl->wsctx) {
801805
n = webSocketsDecode(cl, buf, len);
@@ -896,6 +900,10 @@ rfbPeekExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
896900
struct timeval tv;
897901

898902
while (len > 0) {
903+
if(sock == RFB_INVALID_SOCKET) {
904+
errno = EBADF;
905+
return -1;
906+
}
899907
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
900908
if (cl->sslctx)
901909
n = rfbssl_peek(cl, buf, len);
@@ -1012,6 +1020,10 @@ rfbWriteExact(rfbClientPtr cl,
10121020

10131021
LOCK(cl->outputMutex);
10141022
while (len > 0) {
1023+
if(sock == RFB_INVALID_SOCKET) {
1024+
errno = EBADF;
1025+
return -1;
1026+
}
10151027
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
10161028
if (cl->sslctx)
10171029
n = rfbssl_write(cl, buf, len);

0 commit comments

Comments
 (0)