fix: close the tail items from the targeted re-audit

Resolves the 13 rows still partial in docs/rewrite/notes/review-rv4-
codex.md (details in final-Z5.md):
- Escaped config strings are decoded to raw bytes at every OS boundary:
  Flatpak cwd/argv to D-Bus, screen-file paths, the default config
  template, GHOSTTY_RESOURCES_DIR/TERMINFO/shell integration/
  bindtextdomain consumers, custom shader loading, list-themes hyperlinks.
- osbytes escapes literal U+FDD0 on non-Unix too (bijective everywhere);
  the GTK paste dialog only decodes text that was actually encoded.
- shadertoy: whole-array uses of iChannelTime rebuild a plain float[4]
  from the std140-padded members (naga-validated, MSL offsets checked).
- libghostty-vt: the OSC parser holds caller-allocated storage inline
  and command payloads borrow from it, so ghostty_osc_end performs no
  global allocations (verified from Rust and C).
- crash: aarch64 Linux minidump context fixed; macOS fatal signals record
  siginfo, registers and a fault-safe stack walk.
- tripwire: selectionString map allocation-failure cleanup test ported.
- libghostty-vt emits the versioned soname libghostty-vt.so.0 at build
  time (no patchelf needed at install).

Test Plan:
- cargo test --workspace (3342 passed)
- just check-macos; just check-macos x86_64-apple-darwin;
  just check-windows; just check-wasm
- cargo check --target aarch64-unknown-linux-gnu -p ghostty-crash
This commit is contained in:
ddidderr committed 2026-10-12 08:45:21 +02:00
1 parent 5bfc7bd856
commit 1a13e8b556
49 files changed
+1785 -557

No files matched your search

+30 -17
View File
@@ -791,7 +791,10 @@ impl Subprocess {
// If we have a resources dir then set our env var
if let Some(dir) = &cfg.resources_dir {
log::info!("found Ghostty resources dir: {dir}");
env.insert("GHOSTTY_RESOURCES_DIR", dir.clone());
env.insert(
"GHOSTTY_RESOURCES_DIR",
ghostty_os::osbytes::config_str_to_os(dir),
);
}
// Set our TERM var. This is a bit complicated because we want to use
@@ -810,15 +813,7 @@ impl Subprocess {
// Rust-specific: the in-repo dev resources dir (`<ws>/resources`)
// carries its compiled terminfo inside itself, so prefer that
// when present.
let own = format!("{base}/terminfo");
let terminfo = if std::path::Path::new(&format!("{own}/x/xterm-ghostty")).exists() {
own
} else {
let parent = std::path::Path::new(base)
.parent()
.map_or_else(String::new, |p| p.to_string_lossy().into_owned());
format!("{parent}/terminfo")
};
let terminfo = terminfo_dir(base);
env.insert("TERMINFO", terminfo);
} else {
if cfg!(target_vendor = "apple") {
@@ -1225,31 +1220,49 @@ fn add_ghostty_path(env: &mut EnvMap) {
}
}
/// The `TERMINFO` directory for a resources dir (reversible config-string
/// encoding in, raw OS string out).
fn terminfo_dir(base: &str) -> std::ffi::OsString {
let base = ghostty_os::osbytes::config_str_to_os(base);
let own = std::path::Path::new(&base).join("terminfo");
if own.join("x/xterm-ghostty").exists() {
own.into_os_string()
} else {
let mut parent = std::path::Path::new(&base)
.parent()
.map_or_else(std::ffi::OsString::new, |p| p.as_os_str().to_owned());
parent.push("/terminfo");
parent
}
}
/// macOS: export additional data directories from our application bundle
/// (`XDG_DATA_DIRS` and `MANPATH`).
pub fn darwin_bundle_env(env: &mut EnvMap, resources_dir: &str) {
let xdg_data_dir_key = "XDG_DATA_DIRS";
let data_dir = format!("{resources_dir}/..");
let mut data_dir = ghostty_os::osbytes::config_str_to_os(resources_dir);
data_dir.push("/..");
let current = env.get(xdg_data_dir_key).map_or_else(
|| "/usr/local/share:/usr/share".to_owned(),
|v| v.to_string_lossy().into_owned(),
|| std::ffi::OsString::from("/usr/local/share:/usr/share"),
std::ffi::OsStr::to_owned,
);
env.insert(
xdg_data_dir_key,
ghostty_os::append_env(&current, &data_dir),
ghostty_os::env::append_env_os(&current, &data_dir),
);
let manpath_key = "MANPATH";
let man_dir = format!("{resources_dir}/../man");
let mut man_dir = ghostty_os::osbytes::config_str_to_os(resources_dir);
man_dir.push("/../man");
// Always append with colon in front, as it mean that if
// `MANPATH` is empty, then it should be treated as an extra
// path instead of overriding all paths set by OS.
let current = env
.get(manpath_key)
.map_or_else(String::new, |v| v.to_string_lossy().into_owned());
.map_or_else(std::ffi::OsString::new, std::ffi::OsStr::to_owned);
env.insert(
manpath_key,
ghostty_os::append_env_always(&current, &man_dir),
ghostty_os::env::append_env_always_os(&current, &man_dir),
);
}
+17 -7
View File
@@ -62,6 +62,16 @@ pub struct ShellIntegration {
pub command: Command,
}
/// `<resource_dir>/<rel>` as an OS string. `resource_dir` carries the
/// reversible config-string encoding (it may hold non-UTF-8 bytes), so it is
/// decoded before reaching the filesystem or the child environment.
fn resource_path(resource_dir: &str, rel: &str) -> std::ffi::OsString {
let mut p = ghostty_os::osbytes::config_str_to_os(resource_dir);
p.push("/");
p.push(rel);
p
}
/// Set up the command execution environment for automatic
/// integrated shell integration and return a ShellIntegration
/// struct describing the integration. If integration fails
@@ -239,13 +249,13 @@ fn setup_bash(
}
// Set our new ENV to point to our integration script.
let script_path = format!("{resource_dir}/shell-integration/bash/ghostty.bash");
let script_path = resource_path(resource_dir, "shell-integration/bash/ghostty.bash");
match std::fs::File::open(&script_path) {
Ok(_) => {
env.insert("ENV", script_path);
}
Err(err) => {
log::warn!("unable to open {script_path}: {err}");
log::warn!("unable to open {}: {err}", script_path.to_string_lossy());
env.remove("GHOSTTY_BASH_ENV");
return Ok(None);
}
@@ -278,9 +288,9 @@ fn setup_bash(
/// from `XDG_DATA_DIRS` when integration is complete.
fn setup_xdg_data_dirs(resource_dir: &str, env: &mut EnvMap) -> bool {
// Get our path to the shell integration directory.
let integ_path = format!("{resource_dir}/shell-integration");
let integ_path = resource_path(resource_dir, "shell-integration");
if let Err(err) = std::fs::read_dir(&integ_path) {
log::warn!("unable to open {integ_path}: {err}");
log::warn!("unable to open {}: {err}", integ_path.to_string_lossy());
return false;
}
@@ -297,7 +307,7 @@ fn setup_xdg_data_dirs(resource_dir: &str, env: &mut EnvMap) -> bool {
let current = env
.get(key)
.unwrap_or_else(|| std::ffi::OsStr::new("/usr/local/share:/usr/share"));
let new = prepend_env_os(current, std::ffi::OsStr::new(&integ_path));
let new = prepend_env_os(current, &integ_path);
env.insert(key, new);
true
@@ -374,10 +384,10 @@ fn setup_zsh(command: &Command, resource_dir: &str, env: &mut EnvMap) -> Option<
}
// Set our new ZDOTDIR to point to our shell resource directory.
let integ_path = format!("{resource_dir}/shell-integration/zsh");
let integ_path = resource_path(resource_dir, "shell-integration/zsh");
if !Path::new(&integ_path).is_dir() {
// Mirrors openDirAbsolute failing (missing or not a directory).
log::warn!("unable to open {integ_path}");
log::warn!("unable to open {}", integ_path.to_string_lossy());
return None;
}
env.insert("ZDOTDIR", integ_path);