Commit 4d0fa167 authored by Martin Flöser's avatar Martin Flöser

[client] Fix nullptr dereference in ConfinedPointer and LockedPointer

The setRegion call allows a null region. This means nullptr is an
allowed value which can be passed to ConfinedPointer::setRegion and
LockedPointer::setRegion.

In that case we crash if we try to convert the Region into a wl_region.
Thus add proper nullptr check, just like in
PointerConstraints::lockPointer and ::confinePointer.

Auto test adjusted to cover the condition.
parent 12f2d701
......@@ -226,6 +226,11 @@ void TestPointerConstraints::testLockPointer()
surface->commit(Surface::CommitFlag::None);
QVERIFY(regionChangedSpy.wait());
QCOMPARE(serverLockedPointer->region(), QRegion(0, 5, 10, 20));
// and unset region again
lockedPointer->setRegion(nullptr);
surface->commit(Surface::CommitFlag::None);
QVERIFY(regionChangedSpy.wait());
QCOMPARE(serverLockedPointer->region(), QRegion());
// let's lock the surface
QSignalSpy lockedChangedSpy(serverLockedPointer.data(), &LockedPointerInterface::lockedChanged);
......@@ -326,6 +331,11 @@ void TestPointerConstraints::testConfinePointer()
surface->commit(Surface::CommitFlag::None);
QVERIFY(regionChangedSpy.wait());
QCOMPARE(serverConfinedPointer->region(), QRegion(0, 5, 10, 20));
// and unset region again
confinedPointer->setRegion(nullptr);
surface->commit(Surface::CommitFlag::None);
QVERIFY(regionChangedSpy.wait());
QCOMPARE(serverConfinedPointer->region(), QRegion());
// let's confine the surface
QSignalSpy confinedChangedSpy(serverConfinedPointer.data(), &ConfinedPointerInterface::confinedChanged);
......
......@@ -253,7 +253,11 @@ void LockedPointer::setCursorPositionHint(const QPointF &surfaceLocal)
void LockedPointer::setRegion(Region *region)
{
Q_ASSERT(isValid());
zwp_locked_pointer_v1_set_region(d->lockedpointer, *region);
wl_region *wr = nullptr;
if (region) {
wr = *region;
}
zwp_locked_pointer_v1_set_region(d->lockedpointer, wr);
}
class ConfinedPointer::Private
......@@ -349,7 +353,11 @@ bool ConfinedPointer::isValid() const
void ConfinedPointer::setRegion(Region *region)
{
Q_ASSERT(isValid());
zwp_confined_pointer_v1_set_region(d->confinedpointer, *region);
wl_region *wr = nullptr;
if (region) {
wr = *region;
}
zwp_confined_pointer_v1_set_region(d->confinedpointer, wr);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment