Skip to content

fix: convert blind QUOTED_NULL consumers to E400-aware helpers (Refs #2882) - #3006

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2882-quoted-null-consumers
Nov 7, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2882-quoted-null-consumers

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the PUA/carrier-protocol sweep finding F2 (Refs #2882): a typed
$'\uE002' — U+E002 is QUOTED_NULL_MARKER — arrives E400-escaped
(push_literal_char) as user data, but blind consumers that
cow_replace / contains the bare marker ate it:

  • v=$'\uE002'; printf %s "$v" emitted a stray U+E400 alone (GNU: the raw U+E002 char)
  • echo "$v" emitted nothing
  • "a${v}b" produced ab (char dropped)

Storage was always fine (declare -p, ${#v} correct) — the consumers
were wrong.

Root cause

GNU protects a user CTLNUL byte with CTLESC at read time
(parse.y got_character, ~:5696), so dequote passes
(subst.c remove_quoted_nulls, list_string QUOTED_NULL branch
subst.c:3181-3192) only ever strip the BARE marker. rubash's E400
literal-char escape is the port of that protection, so a consumer of a
registry-zone marker must distinguish the escaped pair (user data)
from the bare char (protocol). Three sites did not:

  • src/executor/command_prepare.rs (expand_quoted_single_name_parameter_word):
    walker-tail restore chain ended in a blind
    cow_replace(QUOTED_NULL_MARKER_STR, "").
  • src/executor/embedded_mutations.rs
    (expand_embedded_parameters_mut_inner tail): same blind
    cow_replace in the non-alternate branch.
  • src/executor/command_prepare.rs (two alternate-word gates): naive
    expanded.contains(QUOTED_NULL_MARKER) deciding the quoted-null
    field-split route — the gate's question is "is the protocol
    present", which is exactly contains_bare_sentinel's contract.

Sibling sites were already converted (#840): conditional.rs and
field_split_values_with_quoted_nulls use
restore_bare_sentinels / contains_bare_sentinel.

Fix

Convert all four blind read points to the E400-aware helper family in
src/executor/markers.rs — restore_bare_sentinels (bare marker →
"", escaped pair copied verbatim) at the two restore chains, and
contains_bare_sentinel at the two gates. No new helpers, no new
public surface, docs/api-ledger.md untouched,
src/lexer/continuation.rs untouched.

Pins

tests/marker_leak_golden.rs gains
user_e002_quoted_null_char_roundtrips_as_data: exact-byte cells for
printf/echo/concat (quoted, braced, unquoted, alternate quoted +
unquoted, assignment round-trip, double char, external argv) plus the
storage controls (declare -p, ${#v}). Fail-first on master:
9 passed; 1 failed (the new test), probe-verified per cell against
GNU bash 5.3.20 under LC_ALL=C.UTF-8.

本 PR 删除了什么

Nothing is deleted. The change converts four blind call sites in
place to the existing E400-aware helpers and adds one golden test;
net line delta is small and positive (comments + test). No code,
tests, or docs are removed.

Residual face found during verification (not fixed here)

case patterns whose double-quoted segment carries the char are a
sibling blind consumer: on the fixed tree case "$v" in "$v") and
case "$v" in *"$v"*) are NOMATCH (GNU: MATCH), while the subject
side, the unquoted pattern form (*$v*), and [[ "$v" == *"$v"* ]]
all agree with GNU. Full probe table is in the lane REPORT §5 —
captain to file it separately or extend #2882 by ruling.

UNVERIFIED-BY-CAPTAIN

Fail-first: the new golden test fails on master (printf emits a stray
U+E400, echo emits nothing, concatenation drops the char) while the 9
pre-existing golden tests pass. Expectations are GNU bash 5.3.20 bytes
under LC_ALL=C.UTF-8, probe-verified per cell.
…2882)

GNU protects a user CTLNUL with CTLESC at read time (parse.y
got_character), so remove_quoted_nulls (subst.c:3181-3192) only ever
strips the BARE marker; rubash's E400 literal-char escape is that
protection's port, and a consumer of the registry-zone marker must
not read the escaped pair as protocol. Convert the four blind read
points to the #840 helper family: restore_bare_sentinels at the two
walker-tail restore chains (command_prepare
expand_quoted_single_name_parameter_word, embedded_mutations tail)
and contains_bare_sentinel at the two alternate field-split gates.

Typed $'\uE002' now round-trips: printf %s emits the raw char, echo
emits it, concatenation keeps it; golden 10/10, full lib 1188/0/4.
@caomengxuan666
caomengxuan666 merged commit c4f397d into master Nov 7, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 8, 2026
…2885)

- markers.rs census: add EXACT entry for __RUBASH_CURRENT_FILE
  (new carrier from #3035/#3047, missing from the E8 census).
- marker_registry_roundtrips: remove all four TYPED_DATA_EXCEPTIONS
  (E002 shapes 1-3 fixed by #2882/#3006; E316 shape 3 by #3016/#3041);
  the stem now asserts every shape round-trips.
- marker-lint-allowlist: delete the two #2882 KNOWN BLIND SPOT entries
  (their own text said delete when #2882 lands), plus two entries made
  stale by master-side changes: set.rs ESC rendering entry (#3044
  restructured the table) and command_prepare contains:QUOTED_NULL_MARKER
  (#3006 converted those consumers to E400-aware helpers).
- marker_leak_golden_pty: un-ignore the read -p cell (#3001 landed the
  read -p decode).
- marker_leak_golden: set-listing C0 scalar cell now expects the
  ansic-quoted GNU form (rubash#3017/#3044), byte-verified against
  GNU bash 5.3.20; the no-marker assertion is unchanged.

Verified on the merged tree (merge bd87ed1 + this commit):
lint OK (117 consts / 258 sites), registry 10/0, PTY 2/0,
golden 20/0, lib 1200/0/4, -D warnings rc=0, hygiene/fmt/CR clean.
caomengxuan666 added a commit that referenced this pull request Nov 8, 2026
…d-consumer lint, registry census (Refs #2885) (#3015)

Marker-leak enforcement gates for rubash#2885 (PUA/carrier protocol
audit, rubash#2879): E6 per-channel golden coverage, E7 blind-consumer
lint with allowlist, E8 registry census + typed round-trip stem.

Captain verification (branch head `1c4a1383`, true base `b4eaed55`,
plus captain merge-time reconciliation `22852ec4` on merged master):
- golden 18/0 on the branch head; registry 10/0; PTY 1 passed /
  1 ignored (the read -p cell, un-ignored at merge time — 2/0 after).
- E6 pristine-tree adjudication: at the E6 commit the golden stem is
  14/4 — the lane's original "18/0" was a stale-binary measurement.
- lib head 1198/0/4 vs base 1196/0/4 (+2 decoder tests moved into
  lib, 0 failed both sides).
- lint OK (117 consts / 262 sites); planted-violation fail-first
  rc=1; lint against base sources reports 103 violations (the gates
  bite); E7 value audit rc=0.
- `RUSTFLAGS="-D warnings"` rc=0; hygiene clean; fmt clean; CR zero.
- Merged tree (after merging master and the reconciliation commit):
  lint OK (117 consts / 258 sites), registry 10/0, PTY 2/0,
  golden 20/0, lib 1200/0/4, -D warnings rc=0, hygiene/fmt/CR clean.
- Merge-time reconciliation: census gained the EXACT entry for
  `__RUBASH_CURRENT_FILE` (#3035's carrier); all four registry
  exceptions removed (E002 via #2882, E316 via #3016); the two #2882
  KNOWN BLIND SPOT allowlist entries deleted, plus two entries made
  stale by master-side changes (#3044 set.rs table, #3006
  command_prepare conversion); one golden cell's expectation updated
  to GNU's ansic-quoted set-listing form (#3017/#3044), byte-verified
  against GNU bash 5.3.20.

本 PR 删除了什么: the branch removes the superseded in-lib marker
test module (its coverage moved into the golden/registry stems) and
obsolete allowlist scaffolding; the captain reconciliation commit
additionally deletes the four registry exceptions and four allowlist
entries listed above. Net across the PR: +2156/−289 before
reconciliation, +10/−21 for the reconciliation commit.

Refs #2885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant