szn

Bug 397 — Format substitute with an empty pattern aborts the server

397. Format substitute with an empty pattern aborts the server: std.mem.replaceOwned panics on a zero-length needle (config/prompt DoS)

Severity: CRITICAL Status: ✅ RESOLVED

expandSubstituteInto slices pattern = content[1..parts[0]] without checking parts[0] > 1. When the closing delimiter immediately follows the pattern delimiter — e.g. #{//x/:session_name} — the pattern is empty, and std.mem.replaceOwned(u8, allocator, value_src, pattern, replacement) (:697) aborts on a zero-length needle. Verified on Zig 0.16.0: a minimal probe calling replaceOwned(u8, a, "abc", "", "x") exits SIGABRT (core dumped).

Any config line (set -g status-left "#{//x/:session_name}" — the pattern between the two leading delimiters is empty) or one command typed at prefix : reaches this path — killing the server process and every attached session. Remote-triggerable by anyone who can write the config or the prompt.

Fix: early-return (append the value unchanged) when pattern.len == 0 before calling replaceOwned.