Reject invalid X11 paste targets
This commit is contained in:
@@ -81,6 +81,9 @@ Each bounded iteration must:
|
||||
## Build, packaging, and acceptance evidence
|
||||
|
||||
- [x] Core tests pass: 20 tests observed after storage mutation failure coverage on 2026-09-10.
|
||||
- [x] X11-feature tests pass: 24 tests, including rejection of `None` and
|
||||
`PointerRoot` as paste targets (plus Docker GTK/X11/package build,
|
||||
2026-09-12).
|
||||
- [x] Rust formatting check passes on 2026-09-10.
|
||||
- [x] X11-only cargo check passes on 2026-09-10.
|
||||
- [x] Full GTK/X11 build passes in the declared Docker environment (Docker build, 2026-09-10).
|
||||
@@ -95,6 +98,8 @@ Each bounded iteration must:
|
||||
packages are still not installed.
|
||||
- Clippy is unavailable in the current Rust toolchain.
|
||||
- No GUI, X11, Cinnamon, or packaging integration tests are present in the tree.
|
||||
- X11 paste now rejects non-concrete focus values before injecting keystrokes;
|
||||
real application-target acceptance remains manual evidence.
|
||||
- Diagnostics previously printed a fixed log filename even though the rolling
|
||||
logger creates date-suffixed files; this is now reported as the log directory.
|
||||
- The initial implementation is now committed; future work must keep the tree
|
||||
|
||||
@@ -40,6 +40,7 @@ impl X11Input {
|
||||
}
|
||||
|
||||
pub fn paste_into(&self, target: xproto::Window) -> Result<()> {
|
||||
validate_paste_target(target)?;
|
||||
self.connection
|
||||
.set_input_focus(xproto::InputFocus::NONE, target, x11rb::CURRENT_TIME)?
|
||||
.check()?;
|
||||
@@ -92,6 +93,16 @@ impl X11Input {
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_paste_target(target: xproto::Window) -> Result<()> {
|
||||
// X11 uses 0 (None) and 1 (PointerRoot) as special focus values; neither
|
||||
// identifies a concrete application window that can safely receive paste.
|
||||
anyhow::ensure!(
|
||||
target > 1,
|
||||
"X11 did not provide a concrete paste target window"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn keycode_for_keysym(
|
||||
connection: &RustConnection,
|
||||
keysym: xproto::Keysym,
|
||||
@@ -111,3 +122,15 @@ fn keycode_for_keysym(
|
||||
}
|
||||
anyhow::bail!("keysym {keysym:#x} is not present in the X11 keyboard mapping")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rejects_non_concrete_focus_targets() {
|
||||
assert!(validate_paste_target(0).is_err());
|
||||
assert!(validate_paste_target(1).is_err());
|
||||
assert!(validate_paste_target(42).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user