summaryrefslogtreecommitdiffstats
path: root/src/client/vnc/vncthread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/vnc/vncthread.cpp')
-rw-r--r--src/client/vnc/vncthread.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp
index 1dbe005..e399e9b 100644
--- a/src/client/vnc/vncthread.cpp
+++ b/src/client/vnc/vncthread.cpp
@@ -36,7 +36,7 @@ VncThread::VncThread(QString host, int port, QString passwd, int quality) :
_port = port;
_passwd = passwd;
_quality = quality;
- _client = NULL;
+ _client = nullptr;
_connected = false;
moveToThread(this);
}
@@ -45,7 +45,7 @@ VncThread::~VncThread()
{
qDebug("VNC worker destructor called.");
Q_ASSERT(_run == false);
- if (_client != NULL) {
+ if (_client != nullptr) {
if (_client->sock != -1)
::close(_client->sock);
_client->sock = -1;
@@ -82,27 +82,27 @@ void VncThread::run()
_client->canHandleNewFBSize = true;
free(_client->serverHost); // in rfbGetClient, serverHost is assigned strdup(""), so free that first.
_client->serverHost = strdup(_host.toUtf8().constData());
- _client->desktopName = NULL;
+ _client->desktopName = nullptr;
_client->serverPort = _port;
_client->GetPassword = &passwdHandler;
_client->GotFrameBufferUpdate = &updateImage;
- _client->frameBuffer = NULL;
+ _client->frameBuffer = nullptr;
// save this instance in vnc-struct for callbacks
rfbClientSetClientData(_client, 0, this);
// start client
- if (rfbInitClient(_client, NULL, NULL)) {
+ if (rfbInitClient(_client, nullptr, nullptr)) {
break; // Success!
}
// Connection failed
- _client = NULL; // InitClient frees the client on failure, so make sure we don't keep an invalid pointer around
+ _client = nullptr; // InitClient frees the client on failure, so make sure we don't keep an invalid pointer around
if (!_run)
break;
// error, let's try again
this->msleep(10 + qrand() % 50);
}
- if (_client != NULL) {
+ if (_client != nullptr) {
qDebug("[%s] Connection successful!", metaObject()->className());
int one = 1;
setsockopt(_client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
@@ -136,7 +136,7 @@ void VncThread::run()
*/
const QString VncThread::getDesktopName() const
{
- if (_client == NULL || _client->desktopName == NULL)
+ if (_client == nullptr || _client->desktopName == nullptr)
return QString();
return QString(_client->desktopName);
}
@@ -189,6 +189,11 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client)
const int width = client->width, height = client->height, depth = 32;
const int size = width * height * (depth / 8);
qDebug("[%s] Remote desktop: %ix%ix%i", t->metaObject()->className(), width, height, depth);
+ if (width < 0 || height < 0 || size < 0) {
+ qWarning() << "IGNORING INVALID FRAMEBUFFER SIZE";
+ client->frameBuffer = nullptr;
+ return false;
+ }
t->_img = QSharedPointer<QImage>(new QImage(width, height, QImage::Format_RGB32));
if (size > t->_img->byteCount()) {
@@ -196,7 +201,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client)
::exit(1);
}
client->frameBuffer = t->_img->bits();
- memset(client->frameBuffer, '\0', size);
+ memset(client->frameBuffer, '\0', (size_t)size);
client->format.trueColour = 1;
client->format.bitsPerPixel = depth;
client->format.redShift = 16;