Commit 541b7596 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

exo: Validate serial numbers passed to DataDevice

This CL adds check to serial numbers passed to StartDrag and
SetSelection of DataDevice, so that serial numbers that do not exist or
serial numbers of invalid event types are ignored.

TEST=manual(Install Crostini and gedit, then confirm copy & paste /
drag & drop working)
BUG=746111

Change-Id: I914ced53a1d96590e24f4c4cb8ed74a43aac659f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255730Reviewed-by: default avatarMitsuru Oshima (slow:gardening) <oshima@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781169}
parent b589f673
......@@ -69,8 +69,7 @@ void DataDevice::StartDrag(DataSource* source,
seat_->StartDrag(source, origin, icon, event_source);
}
void DataDevice::SetSelection(DataSource* source, uint32_t serial) {
// TODO(hirono): Check if serial is valid. crbug.com/746111
void DataDevice::SetSelection(DataSource* source) {
seat_->SetSelection(source);
}
......
......@@ -48,17 +48,15 @@ class DataDevice : public WMHelper::DragDropObserver,
// be null if the data will be transferred only in the client. |origin| is
// the surface which starts the drag and drop operation. |icon| is the
// nullable image which is rendered at the next to cursor while drag
// operation. |serial| is the unique number comes from input events which
// triggers the drag and drop operation.
// operation.
void StartDrag(DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source);
// Sets selection data to the clipboard.
// |source| represents data comes from the client. |serial| is the unique
// number comes from input events which triggers the drag and drop operation.
void SetSelection(DataSource* source, uint32_t serial);
// |source| represents data comes from the client.
void SetSelection(DataSource* source);
// Overridden from WMHelper::DragDropObserver:
void OnDragEntered(const ui::DropTargetEvent& event) override;
......
......@@ -303,6 +303,11 @@ class WaylandDataDeviceDelegate : public DataDeviceDelegate {
uint32_t serial) {
base::Optional<wayland::SerialTracker::EventType> event_type =
serial_tracker_->GetEventType(serial);
if (event_type == base::nullopt) {
LOG(ERROR) << "The serial passed to StartDrag does not exist.";
source->Cancelled();
return;
}
if (event_type == wayland::SerialTracker::EventType::POINTER_BUTTON_DOWN &&
serial_tracker_->GetPointerDownSerial() == serial) {
data_device->StartDrag(
......@@ -314,8 +319,23 @@ class WaylandDataDeviceDelegate : public DataDeviceDelegate {
source, origin, icon,
ui::DragDropTypes::DragEventSource::DRAG_EVENT_SOURCE_TOUCH);
} else {
LOG(ERROR) << "The serial passed to StartDrag does not match its "
"expected types.";
source->Cancelled();
}
}
void SetSelection(DataDevice* data_device,
DataSource* source,
uint32_t serial) {
base::Optional<wayland::SerialTracker::EventType> event_type =
serial_tracker_->GetEventType(serial);
if (event_type == base::nullopt) {
LOG(ERROR) << "The serial passed to SetSelection does not exist.";
source->Cancelled();
return;
}
data_device->SetSelection(source);
}
private:
......@@ -347,10 +367,15 @@ void data_device_start_drag(wl_client* client,
void data_device_set_selection(wl_client* client,
wl_resource* resource,
wl_resource* data_source,
wl_resource* source_resource,
uint32_t serial) {
GetUserDataAs<DataDevice>(resource)->SetSelection(
data_source ? GetUserDataAs<DataSource>(data_source) : nullptr, serial);
DataDevice* data_device = GetUserDataAs<DataDevice>(resource);
static_cast<WaylandDataDeviceDelegate*>(data_device->get_delegate())
->SetSelection(data_device,
source_resource
? GetUserDataAs<DataSource>(source_resource)
: nullptr,
serial);
}
void data_device_release(wl_client* client, wl_resource* resource) {
......
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