Skip to content

Validate DnD actions#4893

Open
robert-ancell wants to merge 1 commit intomainfrom
dnd-validate-actions
Open

Validate DnD actions#4893
robert-ancell wants to merge 1 commit intomainfrom
dnd-validate-actions

Conversation

@robert-ancell
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings April 22, 2026 22:37
@robert-ancell robert-ancell requested a review from a team as a code owner April 22, 2026 22:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Wayland protocol validation for drag-and-drop (DnD) action masks/values, ensuring invalid dnd_action bits are rejected with wl_data_source / wl_data_offer protocol errors.

Changes:

  • Validate wl_data_source.set_actions(dnd_actions) mask and raise invalid_action_mask on invalid bits.
  • Validate wl_data_offer.set_actions(dnd_actions, preferred_action) mask/value and raise invalid_action_mask / invalid_action on invalid inputs.
  • Introduce local helpers for DnD action validation in both the data source and data offer paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/server/frontend_wayland/wl_data_source.cpp Adds mask validation and posts wl_data_source protocol error on invalid action bits.
src/server/frontend_wayland/wl_data_device.cpp Adds mask/value validation for wl_data_offer.set_actions() and posts protocol errors on invalid inputs.

resource,
Error::invalid_action,
"Invalid DnD action 0x%x", preferred_action);
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wl_data_offer.set_actions requires raising a protocol error if preferred_action is not present in the wl_data_offer.source_actions mask (i.e., not supported by the source). Currently only the enum value is validated; please also validate preferred_action against source->actions() (allowing 'none'), and raise Error::invalid_action when it doesn't match.

Suggested change
}
}
if (preferred_action != mw::DataDeviceManager::DndAction::none &&
(source->actions() & preferred_action) == 0)
{
throw mw::ProtocolError(
resource,
Error::invalid_action,
"DnD preferred action 0x%x not supported by source action mask 0x%x",
preferred_action,
source->actions());
}

Copilot uses AI. Check for mistakes.
dnd_action == mw::DataDeviceManager::DndAction::ask;
}

void set_actions(uint32_t dnd_actions, uint32_t preferred_action) override
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wl_data_offer.set_actions is only valid for drag-and-drop offers; this Offer class is also used for clipboard selection offers (see paste_source_set()). Please track whether an Offer represents a DnD operation and raise Error::invalid_offer (or appropriate wl_data_offer error) when set_actions is called on a non-DnD offer.

Copilot uses AI. Check for mistakes.
Comment thread src/server/frontend_wayland/wl_data_device.cpp
Comment on lines +99 to +106
static bool valid_actions(uint32_t dnd_actions)
{
return (dnd_actions & ~(
mw::DataDeviceManager::DndAction::none |
mw::DataDeviceManager::DndAction::copy |
mw::DataDeviceManager::DndAction::move |
mw::DataDeviceManager::DndAction::ask)) == 0;
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid_actions() duplicates the same allowed-bitmask logic that is also introduced in wl_data_source.cpp. To avoid the two sites diverging, consider centralizing the allowed-action mask (e.g., a shared helper/constant in a common frontend_wayland utility header or a single internal function reused by both).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same but wasn't sure where exactly this should live - any suggestions?

Comment thread src/server/frontend_wayland/wl_data_source.cpp
Comment on lines +249 to +256
static bool valid_actions(uint32_t dnd_actions)
{
return (dnd_actions & ~(
mw::DataDeviceManager::DndAction::none |
mw::DataDeviceManager::DndAction::copy |
mw::DataDeviceManager::DndAction::move |
mw::DataDeviceManager::DndAction::ask)) == 0;
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid_actions() is introduced here with the same logic as the helper added in wl_data_device.cpp. Consider centralizing the allowed DnD action mask in one place to reduce duplication and the risk of the two checks drifting over time.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants