From eac497369788353dad6a51a0182a3c45c630a643 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 16 Aug 2017 00:16:57 +0100 Subject: [PATCH] Avoid sending data offers from an invalid source. Summary: A DataDevice will have a source when offers are available, but it can also be legitimately cleared. When calling DataDeviceInterface::sendSelection(DataDeviceInterface *other) if the other data device has no source, we should be setting that we also have no source. In addition this also guards against Seat tracking a DataDeviceInterface with no source when trying to sync x clipboards. BUG: 383054 Reviewers: #plasma Subscribers: graesslin, plasma-devel, #frameworks Tags: #plasma_on_wayland, #frameworks Differential Revision: https://phabricator.kde.org/D7316 --- src/wayland/autotests/client/test_wayland_seat.cpp | 3 +++ src/wayland/datadevice_interface.cpp | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index a74005aa0c..5c4cda3b34 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -1821,6 +1821,9 @@ void TestWaylandSeat::testSelection() QVERIFY(cancelledSpy.isValid()); m_seatInterface->setSelection(ddi); QVERIFY(cancelledSpy.wait()); + + // Copy already cleared selection, BUG 383054 + ddi->sendSelection(ddi); } void TestWaylandSeat::testSelectionNoDataSource() diff --git a/src/wayland/datadevice_interface.cpp b/src/wayland/datadevice_interface.cpp index ce7913acc6..efcbdffc41 100644 --- a/src/wayland/datadevice_interface.cpp +++ b/src/wayland/datadevice_interface.cpp @@ -201,7 +201,12 @@ DataSourceInterface *DataDeviceInterface::selection() const void DataDeviceInterface::sendSelection(DataDeviceInterface *other) { Q_D(); - auto r = d->createDataOffer(other->selection()); + auto otherSelection = other->selection(); + if (!otherSelection) { + sendClearSelection(); + return; + } + auto r = d->createDataOffer(otherSelection); if (!r) { return; }