diff options
author | runge <runge@karlrunge.com> | 2009-05-21 10:32:18 -0400 |
---|---|---|
committer | runge <runge@karlrunge.com> | 2009-05-21 10:32:18 -0400 |
commit | 804335f9d296440bb708ca844f5d89b58b50b0c6 (patch) | |
tree | a59c3c06a829b0a80c5d276d587369e01e92a5fb /libvncserver/main.c | |
parent | 2cd48332e02d9c81f67b2d718ad1feed5b0a808e (diff) | |
download | libtdevnc-804335f9d296440bb708ca844f5d89b58b50b0c6.tar.gz libtdevnc-804335f9d296440bb708ca844f5d89b58b50b0c6.zip |
Thread safety for zrle, zlib, tight.
Proposed tight security type fix for debian bug 517422.
Diffstat (limited to 'libvncserver/main.c')
-rw-r--r-- | libvncserver/main.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/libvncserver/main.c b/libvncserver/main.c index 52bd4e7..1c9a4e7 100644 --- a/libvncserver/main.c +++ b/libvncserver/main.c @@ -444,22 +444,34 @@ clientOutput(void *data) while (1) { haveUpdate = false; while (!haveUpdate) { - if (cl->sock == -1) { - /* Client has disconnected. */ - return NULL; - } - LOCK(cl->updateMutex); - haveUpdate = FB_UPDATE_PENDING(cl); - if(!haveUpdate) { - updateRegion = sraRgnCreateRgn(cl->modifiedRegion); - haveUpdate = sraRgnAnd(updateRegion,cl->requestedRegion); - sraRgnDestroy(updateRegion); - } - - if (!haveUpdate) { - WAIT(cl->updateCond, cl->updateMutex); - } - UNLOCK(cl->updateMutex); + if (cl->sock == -1) { + /* Client has disconnected. */ + return NULL; + } + if (cl->state != RFB_NORMAL || cl->onHold) { + /* just sleep until things get normal */ + usleep(cl->screen->deferUpdateTime * 1000); + continue; + } + + LOCK(cl->updateMutex); + + if (sraRgnEmpty(cl->requestedRegion)) { + ; /* always require a FB Update Request (otherwise can crash.) */ + } else { + haveUpdate = FB_UPDATE_PENDING(cl); + if(!haveUpdate) { + updateRegion = sraRgnCreateRgn(cl->modifiedRegion); + haveUpdate = sraRgnAnd(updateRegion,cl->requestedRegion); + sraRgnDestroy(updateRegion); + } + } + + if (!haveUpdate) { + WAIT(cl->updateCond, cl->updateMutex); + } + + UNLOCK(cl->updateMutex); } /* OK, now, to save bandwidth, wait a little while for more @@ -476,7 +488,9 @@ clientOutput(void *data) /* Now actually send the update. */ rfbIncrClientRef(cl); + LOCK(cl->sendMutex); rfbSendFramebufferUpdate(cl, updateRegion); + UNLOCK(cl->sendMutex); rfbDecrClientRef(cl); sraRgnDestroy(updateRegion); |