diff --git a/src/modules/relaymsg.rs b/src/modules/relaymsg.rs index 70a4df7..a68c8f3 100644 --- a/src/modules/relaymsg.rs +++ b/src/modules/relaymsg.rs @@ -71,7 +71,7 @@ impl Command for RelayMsg { if s.find_nick(nick).is_some() || s.remote_nick.contains_key(&nick.to_ascii_lowercase()) { return bad(s, "RELAYMSG spoofed nick is already in use"); } - if nick.chars().any(|c| FORBIDDEN.contains(c)) { + if nick.chars().any(|c| FORBIDDEN.contains(c) || c.is_whitespace() || c.is_control()) { return bad(s, "Invalid characters in spoofed nick"); } let seps = s diff --git a/src/modules/showfile.rs b/src/modules/showfile.rs index 295d1d5..c50cb17 100644 --- a/src/modules/showfile.rs +++ b/src/modules/showfile.rs @@ -24,13 +24,19 @@ pub fn maybe_show(s: &mut Server, uid: Uid, cmd: &str) -> bool { return false; }; let nick = s.users.get(&uid).map(|u| u.nick.clone()).unwrap_or_default(); - match std::fs::read_to_string(&path) { - Ok(body) => { + // cap the blocking read so a huge (mis)configured file can't stall the core loop + let body = std::fs::File::open(&path).ok().and_then(|f| { + use std::io::Read; + let mut buf = String::new(); + f.take(256 * 1024).read_to_string(&mut buf).ok().map(|_| buf) + }); + match body { + Some(body) => { for line in body.lines() { s.send(uid, format!(":{} NOTICE {nick} :{line}", s.name)); } } - Err(_) => s.send( + None => s.send( uid, format!(":{} NOTICE {nick} :*** {cmd}: file not available.", s.name), ),