Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/bashkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,21 @@ tokio = { version = "1", features = ["rt-multi-thread", "fs"] }
# (TM-DOS-142, interpreter/grow_stack.rs). Already in the tree via Monty.
stacker = "0.1.25"
# markkit builtin (native only: markkit-cli needs tokio's multi-thread rt).
markkit-cli = { version = "0.3.1", default-features = false, features = ["all_formats"], optional = true }
markkit = { version = "0.3.1", default-features = false, features = ["all_formats"], optional = true }
#
# Capped below 0.3.2 to hold the consumer Rust floor. markkit 0.3.2 moved from

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Unrelated change in a parser-fix PR: the markkit/markkit-cli <0.3.2 MSRV cap has nothing to do with 0x1e/0x1f handling, is not mentioned in the PR description, and expands the blast radius (dependency resolution for every consumer). Please split it into its own PR or justify it here; per repo guidance PRs should stay small and unrelated changes preserved out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the principle — this does belong in its own PR, and I raised the same objection myself before adding it. Two corrections and the reason it is here:

It is in the PR description. There is a dedicated "Note on the Rust 1.96 consumer (all) failure" section covering the cause, the evidence and the trade-off. It was added at 10:24 UTC, before this review at 10:33, so the claim that it is unmentioned is out of date.

It is not optional for this PR. markkit 0.3.2 was published today 04:57 UTC (0.3.3 at 05:57) and moved from mail-parser ^0.11 to ^1.0; every mail-parser 1.x declares rust-version = 1.98. The msrv job resolves a fresh consumer while ignoring this repo's Cargo.lock — by design, to catch exactly this drift — so it picked markkit 0.3.3 → mail-parser 1.0.2 and three Rust 1.96 consumer (*, all) jobs went red. Verified it is not this diff:

  • the same job passed on main at 03:06 UTC, before 0.3.2 existed
  • scripts/check-msrv-consumer.py --profile all fails identically on an unmodified checkout: error: rustc 1.96.0 is not supported ... mail-parser@1.0.2 requires rustc 1.98
  • with the cap, the same script completes cargo check on 1.96.0 in 3m52s

So red CI here was not this PR's doing, but leaving it red would have blocked the merge and main's next run would have hit the same wall.

Blast radius is narrower than it looks. Cargo.lock is unchanged — it already pinned 0.3.1 — so only fresh resolution is constrained and the graph the audit and cargo deny see is identical. markkit is optional and off by default, which is why only the all profile was affected. markkit-cli is capped in lockstep because markkit-cli 0.3.3 requires markkit ^0.3.3.

The alternative is raising the consumer floor to 1.98, which drops Rust 1.96/1.97 consumers; AGENTS.md says to preserve that floor, so this takes the conservative option.

Leaving this thread open: splitting it out needs a second branch, and this session may only push to eve/clever-mccarthy-y66s6i. Maintainer's call whether to split it, keep it, or swap it for a floor bump.


Generated by Claude Code

# `mail-parser ^0.11` to `^1.0`, and every mail-parser 1.x declares
# `rust-version = 1.98`, so a fresh external consumer resolved on 1.96 (the
# required `msrv` job, which deliberately ignores this repository's Cargo.lock)
# stops at `rustc 1.96.0 is not supported by mail-parser@1.0.2`. The workspace
# lock already pins 0.3.1, so this only stops fresh resolution drifting past
# the floor -- exactly the drift that job exists to catch. markkit-cli is
# capped in lockstep because markkit-cli 0.3.3 requires `markkit ^0.3.3`.
#
# Lift both together once the floor rises to 1.98 or later on purpose, or once
# markkit's mail-parser dependency supports 1.96 again. See
# knowledge/operations/testing.md#rust-toolchain-and-consumer-compatibility.
markkit-cli = { version = ">=0.3.1, <0.3.2", default-features = false, features = ["all_formats"], optional = true }
markkit = { version = ">=0.3.1, <0.3.2", default-features = false, features = ["all_formats"], optional = true }
# fetchkit builtin (native only). No `reqwest-tls`: all traffic goes through
# bashkit's HttpClient, so fetchkit adds no TLS stack.
fetchkit-cli = { version = "0.7.2", default-features = false, features = ["docs-pdf", "docs-markkit"], optional = true }
Expand Down
8 changes: 5 additions & 3 deletions crates/bashkit/fuzz/fuzz_targets/printf_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ fuzz_target!(|data: &[u8]| {
// The shape need not be in the input -- the message separator's colon
// completes it, so an argument of `Undefined:` renders
// `printf: Undefined:: invalid number` and spells `Undefined::` across
// the join. `assert_fuzz_invariants`' script attribution cannot see a
// join at the slot boundary, so gate at the input layer as
// `arithmetic_fuzz` and `glob_fuzz` do. Nightly run after 304.
// the join. `assert_fuzz_invariants` now attributes that join itself
// (`script_explains` decomposes the pattern, not the whole script), so
// this gate is no longer load-bearing for banned shapes; it is kept
// because it also skips inputs that forge the host canary, which the
// detector hands libFuzzer the bytes to reconstruct.
if bashkit::testing::input_echo_would_trip(input) {
return;
}
Expand Down
146 changes: 114 additions & 32 deletions crates/bashkit/src/parser/lexer.rs

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion crates/bashkit/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5534,7 +5534,10 @@ pub(crate) fn arith_exec_text(raw: &str) -> String {
/// for its own parser (only `\<newline>` is removed); backticks become
/// `$(...)`.
fn heredoc_body_escapes(content: &str) -> String {
if !content.contains(['\\', '`']) && !content.contains("$'") {
// `\u{1e}`/`\u{1f}` are `parse_word`'s quote-boundary markers, so a body
// byte that spells one has to leave here behind the NUL sentinel or it is
// read as a marker and dropped. See `lexer::push_literal_char`.
if !content.contains(['\\', '`', '\u{1e}', '\u{1f}']) && !content.contains("$'") {
return content.to_string();
}
let mut out = String::with_capacity(content.len());
Expand Down Expand Up @@ -5600,6 +5603,10 @@ fn heredoc_body_escapes(content: &str) -> String {
}
out.push(')');
}
'\u{1e}' | '\u{1f}' => {
out.push('\x00');
out.push(c);
}
_ => out.push(c),
}
}
Expand Down
128 changes: 120 additions & 8 deletions crates/bashkit/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,32 @@ fn carries_through_expansion(text: &str, needle: &str) -> bool {
/// does: the harness applies it to every caller, so a new target cannot
/// forget it.
///
/// Padding mirrors [`DIAGNOSTIC_ECHO_PAD`] — a diagnostic wraps the quoted
/// slot in `: ` on both sides, so a shape can be spelled across the join.
/// A shape formed where the slot meets script text *inside* the script is
/// not covered here; [`input_echo_would_trip`] remains the precise gate for
/// that case (run 295's `wZTok:`), which is why the targets that call it
/// keep doing so.
/// # Spelling a shape across the template join
///
/// The echoed slot is an arbitrary *substring* of the script, and the
/// diagnostic wraps it in its own punctuation, so a banned shape can be
/// spelled as `(tail of the template prefix) ++ (script text) ++ (head of the
/// template suffix)` while appearing nowhere in the script. Padding the whole
/// script with [`DIAGNOSTIC_ECHO_PAD`] only sees a join at the script's own
/// ends, so nightly fuzz run 310 went red on two targets at once: `awk_fuzz`
/// on a program of `{ code:…`, which `awk: cmd. line:1: {program}` renders as
/// ` { code:`, and `printf_fuzz` on an operand of `{ code:`, which
/// `printf: {arg}: invalid number` renders the same way. Both joins are
/// interior, so both scripts looked unexplained.
///
/// So the decomposition is applied to the *pattern* instead: drop a leading
/// fragment the template's lead could have supplied and a trailing fragment
/// its trail could have supplied, then ask whether the remaining core is
/// script text. Both pads are two bytes, so this is at most nine `contains`
/// calls, and it loosens only the banned shapes that begin with a space or
/// end in a colon (` { code:`, `Tok::`, `Undefined::`, `internal error:`) —
/// every other shape has no fragment to drop and stays absolute. Those four
/// need it: `printf '%d' 'internal error'` really does render
/// `printf: internal error: invalid number` with no panic behind it.
///
/// An empty core is never accepted. A shape made purely of template text
/// would mean a builtin's own format string spells it, which is a real
/// TM-INF-022 bug and not an echo, so it must keep failing.
///
/// # Residual false negative
///
Expand Down Expand Up @@ -366,8 +386,38 @@ fn carries_through_expansion(text: &str, needle: &str) -> bool {
/// hidden is a formatter whose leak is *triggered* by parsing the shape.
fn script_explains(script: &str, pat: &str) -> bool {
let (lead, trail) = DIAGNOSTIC_ECHO_PAD;
carries_through_expansion(script, pat)
|| carries_through_expansion(&format!("{lead}{}{trail}", script.trim()), pat)
for drop_lead in pad_suffixes(lead) {
let Some(rest) = pat.strip_prefix(drop_lead) else {
continue;
};
for drop_trail in pad_prefixes(trail) {
let Some(core) = rest.strip_suffix(drop_trail) else {
continue;
};
if !core.is_empty() && carries_through_expansion(script, core) {
return true;
}
}
}
false
}

/// Every suffix of `pad`, longest first and the empty one last: what a
/// diagnostic's template prefix can contribute immediately left of an echoed
/// operand. See [`script_explains`].
fn pad_suffixes(pad: &'static str) -> impl Iterator<Item = &'static str> {
pad.char_indices()
.map(move |(i, _)| &pad[i..])
.chain(std::iter::once(""))
}

/// Every prefix of `pad`, shortest first and the empty one last: what a
/// diagnostic's template suffix can contribute immediately right of an echoed
/// operand. See [`script_explains`].
fn pad_prefixes(pad: &'static str) -> impl Iterator<Item = &'static str> {
pad.char_indices()
.map(move |(i, c)| &pad[..i + c.len_utf8()])
.chain(std::iter::once(""))
}

/// Trailing halves of the real-shell diagnostic templates that quote user
Expand Down Expand Up @@ -685,6 +735,68 @@ mod tests {
);
}

#[test]
fn banned_shape_spelled_across_the_template_lead_is_an_echo() {
// `printf: {arg}: invalid number` prefixes the operand with `: `, so
// an operand of `{ code:` spells ` { code:` while the script holds
// only `{ code:`. Nightly fuzz run 310 (`printf_fuzz`, `awk_fuzz`).
let result = ExecResult {
stderr: "bash: line 1: printf: { code:: invalid number".into(),
..Default::default()
};
assert_fuzz_invariants(&result, "printf '%d' '{ code:'", "join_lead", &[]);
}

#[test]
fn banned_shape_spelled_across_the_template_trail_is_an_echo() {
// Run 295: `wZTok:` renders `bash: line 1: wZTok:: syntax error …`,
// where the message separator's colon completes `Tok::`.
let result = ExecResult {
stderr: "bash: line 1: wZTok:: syntax error in expression".into(),
..Default::default()
};
assert_fuzz_invariants(&result, "echo $((wZTok:))", "join_trail", &[]);
}

#[test]
fn banned_shape_spelled_across_both_template_joins_is_an_echo() {
// Both halves at once: an operand of `{ code` renders
// `printf: { code: invalid number`, whose ` { code:` is the lead's
// space plus the operand plus the separator's colon.
let result = ExecResult {
stderr: "bash: line 1: printf: { code: invalid number".into(),
..Default::default()
};
assert_fuzz_invariants(&result, "printf '%d' '{ code'", "join_both", &[]);
}

#[test]
#[should_panic(expected = "stderr leaks banned shape ` { code:`")]
fn template_join_attribution_still_needs_the_core_in_the_script() {
// Decomposition only forgives the pad fragments. A script that spells
// none of the cores (` { code:`, `{ code:`, ` { code`, `{ code`) is
// still unexplained, so a Debug shape there is a real leak.
let result = ExecResult {
stderr: "parse failed: { code: 3 } at offset 1".into(),
..Default::default()
};
assert_fuzz_invariants(&result, "jq '.a' f.json", "join_unexplained", &[]);
}

#[test]
#[should_panic(expected = "stderr leaks banned shape `: `")]
fn a_shape_made_only_of_template_text_is_still_a_leak() {
// An empty core would mean the shape is entirely the diagnostic's own
// punctuation — a format string spelling it, not an echo — so it must
// not be excused. Exercised through the per-tool list, since no
// universal shape is a substring of the pad.
let result = ExecResult {
stderr: "tool: boom".into(),
..Default::default()
};
assert_fuzz_invariants(&result, "tool run", "empty_core", &[": "]);
}

#[test]
#[should_panic(expected = "stderr leaks banned shape `Undefined::`")]
fn banned_shape_absent_from_the_script_is_still_a_leak() {
Expand Down
76 changes: 76 additions & 0 deletions crates/bashkit/tests/fuzz_crash_regressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,79 @@ async fn a_bare_banned_shape_framed_only_by_template_text_is_an_echo() {
fuzz_exec(&mut bash, &script, "printf_fuzz", &[]).await;
}
}

/// `awk_fuzz` run 310: the awk program was `{ code:…`, and
/// `awk: cmd. line:1: {program}` prefixes it with `line:1: `. The Debug shape
/// ` { code:` is spelled across that join — the leading space is the
/// template's, the rest is the program — so it appears nowhere in the script.
/// Whole-script padding cannot see an interior join, which is why
/// `script_explains` pads the *pattern* instead.
#[tokio::test]
async fn awk_crash_code_shape_across_template_join_is_an_echo_not_a_leak() {
fuzz_init();
let data = b64("eyBjb2RlOgAAAAAAAABobw==");
let input = std::str::from_utf8(&data).expect("crash unit is UTF-8");
let (program, input_data) = match input.find('\n') {
Some(pos) => (&input[..pos], &input[pos + 1..]),
None => (input, "a b c\n1 2 3\n"),
};
let mut bash = bash(4096);
for script in [
format!("echo '{}' | awk '{}'", sq(input_data), sq(program)),
format!("echo '{}' | awk -F: '{}'", sq(input_data), sq(program)),
] {
fuzz_exec(&mut bash, &script, "awk_fuzz", &[]).await;
}
}

/// `printf_fuzz` run 310: the same interior join one builtin further on.
/// `printf: {arg}: invalid number` prefixes the operand with `printf: `, so an
/// operand of `{ code:` spells ` { code:`. The target's
/// `input_echo_would_trip` gate pads the whole input and so misses it too;
/// attribution in the harness is what has to cover this.
#[tokio::test]
async fn printf_crash_code_shape_across_template_join_is_an_echo_not_a_leak() {
fuzz_init();
let data = b64("JWNgY2B7IGNvZGU6Cgp7IGNvZGU6Cgo=");
let input = std::str::from_utf8(&data).expect("crash unit is UTF-8");
let (format_str, args_str) = match input.find('\n') {
Some(pos) => (&input[..pos], &input[pos + 1..]),
None => (input, ""),
};
let args_joined = args_str
.lines()
.map(|a| format!("'{}'", sq(a)))
.collect::<Vec<_>>()
.join(" ");
let mut bash = bash(4096);
for script in [
format!("printf '{}' {}", sq(format_str), args_joined),
format!("printf -v result '{}' {}", sq(format_str), args_joined),
format!("printf '%d %o %x' {args_joined}"),
] {
fuzz_exec(&mut bash, &script, "printf_fuzz", &[]).await;
}
}

/// `tomlq_fuzz` run 310: the query held `target/debug/\x1f\x1f\x1fdeps/`, which
/// is *not* the banned host path — until the diagnostic sanitizes the control
/// bytes out of the quoted operand and `tomlq: path '…' not found` reads
/// `target/debug/deps/`. Attribution compares against the raw script, so it
/// has to account for the same sanitization the renderer applies.
#[tokio::test]
async fn tomlq_crash_control_bytes_sanitized_into_host_path_is_an_echo() {
fuzz_init();
let data = b64("UwAAAAAnJ0BAQEAnCicAAAAAAAoAdGFyZ2V0L2RlYnVnLx8fH2RlcHMvOgE=");
let input = std::str::from_utf8(&data).expect("crash unit is UTF-8");
let (toml_doc, query) = match input.find('\n') {
Some(pos) => (&input[..pos], &input[pos + 1..]),
None => (input, "."),
};
let mut bash = bash(4096);
for script in [
format!("echo '{}' | tomlq '{}'", sq(toml_doc), sq(query)),
format!("echo '{}' | tomlq", sq(toml_doc)),
] {
fuzz_exec(&mut bash, &script, "tomlq_fuzz", &[]).await;
}
}
1 change: 1 addition & 0 deletions crates/bashkit/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod markkit_builtin_tests;
pub mod memory_growth_security_tests;
pub mod mixed_control_tests;
pub mod output_file_tests;
pub mod quote_marker_byte_tests;
pub mod streaming_command_tests;
pub mod tar_files_from_budget_tests;
// Both assert named-IANA-zone behavior, which only exists with `tzdata`.
Expand Down
Loading
Loading