1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00

window: x11: avoid potential crash when pasting non-utf8 text

This might "break" eg: pasting from apps that just use ATOM_STRING
and that happen to have utf-8 compatible text.

Ideally the get_text_property interface would expose the actual
text encoding in the returned data and allow the application to
"do stuff" with it.

refs: https://github.com/meh/rust-xcb-util/issues/21
This commit is contained in:
Wez Furlong 2022-02-13 07:34:47 -07:00
parent a79fc87586
commit c9f1f0e12c

View File

@ -574,16 +574,21 @@ impl XWindowInner {
let conn = self.conn(); let conn = self.conn();
log::trace!( log::trace!(
"SELECTION_NOTIFY received selection={} (prim={} clip={}) target={} property={}", "SELECTION_NOTIFY received selection={} (prim={} clip={}) target={} property={} utf8={}",
selection.selection(), selection.selection(),
xcb::ATOM_PRIMARY, xcb::ATOM_PRIMARY,
conn.atom_clipboard, conn.atom_clipboard,
selection.target(), selection.target(),
selection.property() selection.property(),
self.conn().atom_utf8_string,
); );
if let Some(clipboard) = self.selection_atom_to_clipboard(selection.selection()) { if let Some(clipboard) = self.selection_atom_to_clipboard(selection.selection()) {
if selection.property() != xcb::NONE { if selection.property() != xcb::NONE
// Restrict to strictly UTF-8 to avoid crashing; see
// <https://github.com/meh/rust-xcb-util/issues/21>
&& selection.target() == self.conn().atom_utf8_string
{
match xcb_util::icccm::get_text_property( match xcb_util::icccm::get_text_property(
&conn, &conn,
selection.requestor(), selection.requestor(),