Skip to content

Commit 2950700

Browse files
author
Christian Beier
committed
Merge branch 'master' into multicastvnc
2 parents 994d854 + 5b4be28 commit 2950700

5 files changed

Lines changed: 46 additions & 21 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ endif(WITH_THREADS)
144144

145145

146146
if(WITH_GNUTLS)
147-
find_package(GnuTLS)
147+
find_package(GnuTLS 3.4.0)
148148
endif(WITH_GNUTLS)
149149

150150

libvncclient/rfbproto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ HandleRFBServerMessage(rfbClient* client)
21682168
if (!ReadFromRFBServer(client, ((char *)&screen), sz_rfbExtDesktopScreen)) {
21692169
return FALSE;
21702170
}
2171-
if (screen.id != 0) {
2171+
if (screen.id != 0 && screen.width && screen.height) {
21722172
client->screen = screen;
21732173
} else {
21742174
invalidScreen = TRUE;

libvncclient/tls_gnutls.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#include <gnutls/x509.h>
2323
#include <rfb/rfbclient.h>
2424
#include <errno.h>
25-
#ifdef WIN32
26-
#include <windows.h> /* for Sleep() */
27-
#define sleep(X) Sleep(1000*X) /* MinGW32 has no sleep() */
28-
#endif
2925
#include "tls.h"
3026

3127

@@ -228,6 +224,27 @@ PullTLS(gnutls_transport_ptr_t transport, void *data, size_t len)
228224
}
229225
}
230226

227+
static int
228+
PullTimeout(gnutls_transport_ptr_t transport, unsigned int timeout)
229+
{
230+
rfbClient *client = (rfbClient*)transport;
231+
int ret;
232+
233+
while (1)
234+
{
235+
ret = gnutls_system_recv_timeout((gnutls_transport_ptr_t)(long)client->sock, timeout);
236+
237+
if (ret < 0)
238+
{
239+
#ifdef WIN32
240+
WSAtoTLSErrno((gnutls_session_t*)&client->tlsSession);
241+
#endif
242+
if (errno == EINTR) continue;
243+
}
244+
return ret;
245+
}
246+
}
247+
231248
static rfbBool
232249
InitializeTLSSession(rfbClient* client, rfbBool anonTLS)
233250
{
@@ -252,6 +269,9 @@ InitializeTLSSession(rfbClient* client, rfbBool anonTLS)
252269
gnutls_transport_set_push_function((gnutls_session_t)client->tlsSession, PushTLS);
253270
gnutls_transport_set_pull_function((gnutls_session_t)client->tlsSession, PullTLS);
254271

272+
gnutls_transport_set_pull_timeout_function((gnutls_session_t)client->tlsSession, PullTimeout);
273+
gnutls_handshake_set_timeout((gnutls_session_t)client->tlsSession, 15000);
274+
255275
INIT_MUTEX(client->tlsRwMutex);
256276

257277
rfbClientLog("TLS session initialized.\n");
@@ -279,27 +299,16 @@ SetTLSAnonCredential(rfbClient* client)
279299
static rfbBool
280300
HandshakeTLS(rfbClient* client)
281301
{
282-
int timeout = 15;
283302
int ret;
284303

285-
while (timeout > 0 && (ret = gnutls_handshake((gnutls_session_t)client->tlsSession)) < 0)
304+
while ((ret = gnutls_handshake((gnutls_session_t)client->tlsSession)) < 0)
286305
{
287306
if (!gnutls_error_is_fatal(ret))
288307
{
289-
rfbClientLog("TLS handshake blocking.\n");
290-
sleep(1);
291-
timeout--;
308+
rfbClientLog("TLS handshake got a temporary error: %s.\n", gnutls_strerror(ret));
292309
continue;
293310
}
294-
rfbClientLog("TLS handshake failed: %s.\n", gnutls_strerror(ret));
295-
296-
FreeTLS(client);
297-
return FALSE;
298-
}
299-
300-
if (timeout <= 0)
301-
{
302-
rfbClientLog("TLS handshake timeout.\n");
311+
rfbClientLog("TLS handshake failed: %s\n", gnutls_strerror(ret));
303312
FreeTLS(client);
304313
return FALSE;
305314
}

libvncserver/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,16 @@ void rfbNewFramebuffer(rfbScreenInfoPtr screen, char *framebuffer,
11641164
rfbClientIteratorPtr iterator;
11651165
rfbClientPtr cl;
11661166

1167+
/* Lock out client reads. */
1168+
iterator = rfbGetClientIterator(screen);
1169+
while ((cl = rfbClientIteratorNext(iterator))) {
1170+
LOCK(cl->sendMutex);
1171+
}
1172+
rfbReleaseClientIterator(iterator);
1173+
1174+
/* Prevent cursor drawing into framebuffer */
1175+
LOCK(screen->cursorMutex);
1176+
11671177
/* Update information in the screenInfo structure */
11681178

11691179
old_format = screen->serverFormat;
@@ -1223,8 +1233,14 @@ void rfbNewFramebuffer(rfbScreenInfoPtr screen, char *framebuffer,
12231233

12241234
TSIGNAL(cl->updateCond);
12251235
UNLOCK(cl->updateMutex);
1236+
1237+
/* Swapping frame buffers finished, re-enable client reads. */
1238+
UNLOCK(cl->sendMutex);
12261239
}
12271240
rfbReleaseClientIterator(iterator);
1241+
1242+
/* Re-enable cursor drawing into framebuffer */
1243+
UNLOCK(screen->cursorMutex);
12281244
}
12291245

12301246
/* hang up on all clients and free all reserved memory */

libvncserver/tight.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ rfbNumCodedRectsTight(rfbClientPtr cl,
212212
maxRectSize = tightConf[cl->tightCompressLevel].maxRectSize;
213213
maxRectWidth = tightConf[cl->tightCompressLevel].maxRectWidth;
214214

215-
if (w > maxRectWidth || w * h > maxRectSize) {
215+
if (maxRectWidth > 0 && (w > maxRectWidth || w * h > maxRectSize)) {
216216
subrectMaxWidth = (w > maxRectWidth) ? maxRectWidth : w;
217217
subrectMaxHeight = maxRectSize / subrectMaxWidth;
218218
return (((w - 1) / maxRectWidth + 1) *

0 commit comments

Comments
 (0)