From c7afd1ea752aeff0310ac7c6b78d091ac360c760 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 15:38:57 +0100 Subject: 0.4.3: kill process groups, bound bash output, keep the key out of tool env - setsid-style process group kill on timeout and on Ctrl-C - 64 MiB RLIMIT_FSIZE so a runaway command cannot fill /tmp - OPENCODE_API_KEY removed from child environment - sessions 0600/0700, history 0600 and trimmed --- src/line.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/line.rs') diff --git a/src/line.rs b/src/line.rs index 6b93f06..4989734 100644 --- a/src/line.rs +++ b/src/line.rs @@ -1,4 +1,5 @@ use std::io::{self, IsTerminal, Write}; +use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; use crossterm::cursor::{MoveToColumn, MoveUp}; @@ -324,7 +325,8 @@ fn history_path() -> PathBuf { } fn load_history() -> Vec { - let text = std::fs::read_to_string(history_path()).unwrap_or_default(); + let path = history_path(); + let text = std::fs::read_to_string(&path).unwrap_or_default(); let mut lines: Vec = text .split('\n') .filter(|line| !line.trim().is_empty() && !line.starts_with('\u{0}')) @@ -332,6 +334,11 @@ fn load_history() -> Vec { .collect(); if lines.len() > HISTORY_LIMIT { lines.drain(..lines.len() - HISTORY_LIMIT); + // Keep the file from growing without bound, not just the in-memory list. + if lines.len() * 2 < text.lines().count() { + let body: Vec = lines.iter().map(|line| line.replace('\n', "\u{0}")).collect(); + let _ = std::fs::write(&path, format!("{}\n", body.join("\n"))); + } } lines } @@ -341,11 +348,15 @@ fn append_history(line: &str) { if let Some(parent) = path.parent() { let _ = std::fs::create_dir_all(parent); } + if let Some(parent) = path.parent() { + let _ = std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700)); + } if let Ok(mut file) = std::fs::OpenOptions::new() .create(true) .append(true) .open(&path) { + let _ = std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)); // One record per line, so newlines inside a prompt are escaped. let _ = writeln!(file, "{}", line.replace('\n', "\u{0}")); } -- cgit v1.2.3