From e251c960d9745eb791452543129b3fa173a1279e Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Fri, 23 Oct 2026 01:57:00 +0100 Subject: [PATCH] =?UTF-8?q?#3692:=20review=20=E2=80=94=20doc=20comments=20?= =?UTF-8?q?on=20the=20functions=20the=20Zotero=20hardening=20added=20or=20?= =?UTF-8?q?changed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01CX1hMKX28764Lrx5moxs1o --- apps/wordcraft-cli/src/main.rs | 2 ++ crates/zotero/src/bridge.rs | 1 + crates/zotero/src/peer.rs | 4 ++++ crates/zotero/src/rich.rs | 3 +++ 4 files changed, 10 insertions(+) diff --git a/apps/wordcraft-cli/src/main.rs b/apps/wordcraft-cli/src/main.rs index 0817d18b34..c8e46c93cc 100644 --- a/apps/wordcraft-cli/src/main.rs +++ b/apps/wordcraft-cli/src/main.rs @@ -387,6 +387,8 @@ fn valid_connect_addr(addr: &str) -> bool { !host.is_empty() && port.parse::().is_ok() } +/// Run the subcommand named by `args` (the command line after the program name). Files named +/// there are opened by their real names, which may not be valid Unicode. fn run>(args: &[S]) -> Result<(), Failure> { let script_path = script_operand(args); let (args, file) = text_args(args)?; diff --git a/crates/zotero/src/bridge.rs b/crates/zotero/src/bridge.rs index 36cb2d0b44..50ea5fcd5f 100644 --- a/crates/zotero/src/bridge.rs +++ b/crates/zotero/src/bridge.rs @@ -194,6 +194,7 @@ impl Bridge { } } + /// Answer one call by its method name; [`Bridge::handle`] wraps it so a panic becomes an error. fn dispatch(&mut self, s: &mut Session, host: &mut dyn Host, c: &Call) -> R { match c.method.as_str() { "Application_getActiveDocument" => { diff --git a/crates/zotero/src/peer.rs b/crates/zotero/src/peer.rs index e808f03d2d..8e6ea6c4e4 100644 --- a/crates/zotero/src/peer.rs +++ b/crates/zotero/src/peer.rs @@ -29,6 +29,7 @@ pub(crate) fn check(stream: &TcpStream) -> Result<(), ZoteroError> { owner_check(local, peer) } +/// Refuse a listener at `peer` that the kernel's socket tables say belongs to another user. #[cfg(any(target_os = "linux", target_os = "android"))] fn owner_check(local: SocketAddr, peer: SocketAddr) -> Result<(), ZoteroError> { use std::io::Read; @@ -48,6 +49,7 @@ fn owner_check(local: SocketAddr, peer: SocketAddr) -> Result<(), ZoteroError> { same_owner(&table, local, peer, me) } +/// No socket table to read here: the loopback rule alone decides. #[cfg(not(any(target_os = "linux", target_os = "android")))] fn owner_check(_local: SocketAddr, _peer: SocketAddr) -> Result<(), ZoteroError> { Ok(()) @@ -124,12 +126,14 @@ mod tests { format!("{ip}:{:04X}", a.port()) } + /// A socket table row for the connection from `l` to `r`, owned by `uid`. fn row(l: SocketAddr, r: SocketAddr, uid: u32) -> String { format!(" 0: {} {} 01 00000000:00000000 00:00000000 00000000 {uid:>4} 0 12345 1 0000000000000000 20 4 30 10 -1\n", hex(l), hex(r)) } const HEADER: &str = " sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode\n"; + /// Our side and Zotero's listening side of a loopback connection. fn addrs() -> (SocketAddr, SocketAddr) { ("127.0.0.1:41234".parse().unwrap(), "127.0.0.1:23116".parse().unwrap()) } diff --git a/crates/zotero/src/rich.rs b/crates/zotero/src/rich.rs index 6285ecf3eb..7ff3377f1c 100644 --- a/crates/zotero/src/rich.rs +++ b/crates/zotero/src/rich.rs @@ -40,6 +40,9 @@ fn style_props(base: &CharProps, src: &CharProps) -> CharProps { p } +/// The body paragraphs of `d` (Zotero's RTF or HTML, read), at most [`MAX_PARAS`], formatted on +/// top of `base` with the run styling they carry (past [`MAX_RUNS`] runs, text keeps the +/// formatting before it). Objects are dropped. fn from_doc(d: &Document, base: &CharProps) -> Vec { let mut out = Vec::new(); let mut runs = 0usize;