From 1771b8d7c6fd052e6a16b109cc841e69fe180e2d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 29 Jul 2018 13:21:28 +0200 Subject: QFbCursor: Avoid nullptr access when QT_QPA_FB_HIDECURSOR is 0 When the environment variable QT_QPA_FB_HIDECURSOR is set to 0, the two class members mCursorImage and mDeviceListener are nullptr but this was not checked in the functions afterwards. Task-number: QTBUG-64844 Change-Id: Ic0fd6a09851777643e59bedf2c006a6bb9a36801 Reviewed-by: Laszlo Agocs --- src/platformsupport/fbconvenience/qfbcursor.cpp | 25 +++++++++++++++++-------- src/platformsupport/fbconvenience/qfbcursor_p.h | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/platformsupport/fbconvenience/qfbcursor.cpp b/src/platformsupport/fbconvenience/qfbcursor.cpp index 7daf3f4d0c..e0f6b69e77 100644 --- a/src/platformsupport/fbconvenience/qfbcursor.cpp +++ b/src/platformsupport/fbconvenience/qfbcursor.cpp @@ -63,9 +63,9 @@ QFbCursor::QFbCursor(QFbScreen *screen) mCursorImage(nullptr), mDeviceListener(nullptr) { - QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR"); - if (!hideCursorVal.isEmpty()) - mVisible = hideCursorVal.toInt() == 0; + const char *envVar = "QT_QPA_FB_HIDECURSOR"; + if (qEnvironmentVariableIsSet(envVar)) + mVisible = qEnvironmentVariableIntValue(envVar) == 0; if (!mVisible) return; @@ -83,7 +83,7 @@ QFbCursor::~QFbCursor() delete mDeviceListener; } -QRect QFbCursor::getCurrentRect() +QRect QFbCursor::getCurrentRect() const { QRect rect = mCursorImage->image()->rect().translated(-mCursorImage->hotspot().x(), -mCursorImage->hotspot().y()); @@ -102,6 +102,8 @@ void QFbCursor::setPos(const QPoint &pos) { QGuiApplicationPrivate::inputDeviceManager()->setCursorPos(pos); m_pos = pos; + if (!mVisible) + return; mCurrentRect = getCurrentRect(); if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft()))) setDirty(); @@ -112,6 +114,8 @@ void QFbCursor::pointerEvent(const QMouseEvent &e) if (e.type() != QEvent::MouseMove) return; m_pos = e.screenPos().toPoint(); + if (!mVisible) + return; mCurrentRect = getCurrentRect(); if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft()))) setDirty(); @@ -149,23 +153,28 @@ QRect QFbCursor::dirtyRect() void QFbCursor::setCursor(Qt::CursorShape shape) { - mCursorImage->set(shape); + if (mCursorImage) + mCursorImage->set(shape); } void QFbCursor::setCursor(const QImage &image, int hotx, int hoty) { - mCursorImage->set(image, hotx, hoty); + if (mCursorImage) + mCursorImage->set(image, hotx, hoty); } void QFbCursor::setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY) { - mCursorImage->set(data, mask, width, height, hotX, hotY); + if (mCursorImage) + mCursorImage->set(data, mask, width, height, hotX, hotY); } #ifndef QT_NO_CURSOR void QFbCursor::changeCursor(QCursor * widgetCursor, QWindow *window) { Q_UNUSED(window); + if (!mVisible) + return; const Qt::CursorShape shape = widgetCursor ? widgetCursor->shape() : Qt::ArrowCursor; if (shape == Qt::BitmapCursor) { @@ -196,7 +205,7 @@ void QFbCursor::setDirty() void QFbCursor::updateMouseStatus() { - mVisible = mDeviceListener->hasMouse(); + mVisible = mDeviceListener ? mDeviceListener->hasMouse() : false; mScreen->setDirty(mVisible ? getCurrentRect() : lastPainted()); } diff --git a/src/platformsupport/fbconvenience/qfbcursor_p.h b/src/platformsupport/fbconvenience/qfbcursor_p.h index beda10a5f3..cc36a2411b 100644 --- a/src/platformsupport/fbconvenience/qfbcursor_p.h +++ b/src/platformsupport/fbconvenience/qfbcursor_p.h @@ -105,7 +105,7 @@ private: void setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY); void setCursor(Qt::CursorShape shape); void setCursor(const QImage &image, int hotx, int hoty); - QRect getCurrentRect(); + QRect getCurrentRect() const; bool mVisible; QFbScreen *mScreen; -- cgit v1.2.3