Skip to content

fix: round 3 slice 2 — 20 fixes (hunt #1455–#1465, #1477–#1487) - #1502

Merged
caomengxuan666 merged 21 commits into
masterfrom
fix/bulk-r3-slice2
Oct 24, 2026
Merged

caomengxuan666 merged 21 commits into
masterfrom
fix/bulk-r3-slice2

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Round 3, slice 2 — rolling delivery of the bulk-fix wave: 21 commits (one per issue) from hunt batches #1455–#1465 and #1477–#1487. Every fix was reproduced and verified against a self-built GNU bash 5.3.20 oracle at cluster level before landing. Full integration verification (lib suite + 246-case differential) is running; results will be posted as a comment on this PR before merge.

Fixed

Fixes #1455
Fixes #1456
Fixes #1457
Fixes #1458
Fixes #1459
Fixes #1460
Fixes #1462
Fixes #1464
Fixes #1465
Fixes #1477
Fixes #1478
Fixes #1479
Fixes #1480
Fixes #1481
Fixes #1482
Fixes #1483
Fixes #1484
Fixes #1485
Fixes #1486
Fixes #1487

Partial progress (not closed by this PR)

Refs #1463

Notes

… decode (#1455)

decode_double_quotes_in_quoted_parameter_word flat-scanned the ${...}
word of a double-quoted ${parameter:-word} expansion, turning the
command substitution body's own quote characters into DATA_SQUOTE
markers that leaked into the inner parse (printf received 'x and y').
GNU treats the unit as a self-contained parse unit whose interior is
re-read when the body executes: parse.y:4451 parse_comsub,
parse.y:3877 parse_matched_pair, subst.c:7143 command_substitute.
Copy $(...) (via skip_parenthesized_unit_corrected) and `...` units
verbatim in the decode loop.
…rds (#1456)

"pre${arr[@]%.txt}" collapsed to one space-joined word because only
the unsliced \@-list had a segment in the quoted-word segment expander.
GNU runs chk_atstar (subst.c:7635-7639) before the operator switch in
parameter_brace_expand (subst.c:10119-10128), so the @-list boundaries
survive pattern removal/replacement/case operators and each element is
transformed separately. Add a whitelist-admitted AtModified segment to
both segment scanners (bodies that parse through the pure operator
parsers with target exactly \@ or name[@]; no $( or backtick), resolve
it through the whole-word per-element helpers.
read -a silently overwrote readonly arrays. GNU locates the -a target
in read.def's assign_vars through builtins/common.c:988
builtin_find_indexed_array -> arrayfunc.c:454
find_or_make_array_variable, whose assignment flag fails readonly
targets with err_readonly after the input is consumed; the value is
kept and the builtin returns 1. Add the resolved-name readonly guard
at the post-read store and at the -n 0 early store. The -t 0 branch is
deliberately uncovered: read.def:395-398 returns the
input-availability result before the array is ever located.
declare -lu / -ul / -l -u used last-option-wins, leaving -u in effect.
GNU builtins/declare.def:341-356 sets each case option's bit in
flags_on AND adds the other two case attributes to flags_off;
application (declare.def:525-527) is VSETATTR(flags_on) then
VUNSETATTR(flags_off), so combined case options cancel out entirely.
Mirror that: the parser records cross-clears in the unset_* fields and
the apply layer marks/converts by the effective attribute
(on && !off).
…fallback (#1459)

A chmod-644 text file was run as a shell script with status 0. The
ENOEXEC fallback (execute_cmd.c:6139-6233 shell_execve) only applies
when execve actually refuses with ENOEXEC; a file without any execute
bit fails with EACCES and GNU reports Permission denied / 126
(findcmd.c file_to_lose_on semantics). Gate both ENOEXEC classifiers
on is_executable_file: is_enoexec_candidate and the synthetic-ENOEXEC
pre-spawn branch in spawn_external_process, so non-executable files
reach the real spawn and its EACCES diagnostic.
…l fd (#1460)

tee >(cat > out) wrote nothing: the child received the literal
/dev/fd/63 word but no such descriptor existed in it (the shell-side
endpoint is a buffered temp file). The unix materializer only backed
READ endpoints with pipes. Mirror the read side for
FdWriteEndpoint::ProcessSubstitution: open the backing temp file in
the parent and pin it at fd N in the child via unix_fd_attach, so the
child's opens of /dev/fd/N land on the file the post-command drain
feeds to the body. GNU subst.c:6362 process_substitute hands the
child the real pipe write end under the same name; rubash#438 fixed
the input direction, the Windows branch (rubash#1223) already
resolved the write endpoint to its temp path.
…ever shadow a PATH sed (#1462)

Three layers of the pipeline sed bridge diverging from GNU:
- [[:space:]] and friends parsed as the literal character set
  {[, :, s, p, a, c, e} plus a ']' atom, so named classes never
  matched. Expand [:name:] items inside bracket expressions to their
  C-locale ranges (POSIX.1-2017 9.3.5); unknown class names fail the
  parse, like GNU sed's invalid character class name error.
- apply_simple_sed_line swallowed BRE parse failures per line and
  passed input through, silently shadowing the real sed with wrong
  output. Validate every substitution pattern up front; any failure
  declines the whole fast path.
- The pipeline stage intercepted 'sed' even when a sed resolves in
  PATH. GNU has no sed builtin (findcmd.c PATH resolution); only
  serve the bridge when no sed is resolvable.
, partial)

assignment_value_needs_tilde_expansion / expand_assignment_tilde_value
split the value at every ':' blindly, so a tilde segment inside a
quoted span of a ${...} operator word ('${u:-'a:~'}' -> 'a:~') was
expanded or armed wrongly. Split only at unquoted ':' with quote
state tracked over raw quotes, the \x17/\x18 data-quote carriers and
the assignment-hoist sentinels, skipping $(...) and backquote units
whole (parse.y:4451 parse_comsub). GNU anchor: subst.c:11410-11460
internal_tilde in the W_ASSIGNMENT walk. Plain assignment words are
intentionally unchanged: the lexer strips their quotes before this
layer (word.rs remove_shell_quotes_with_posix) and only a whole-value
quoted marker survives, so per-segment quote positions are
unrecoverable here — see REPORT.md for the evidence and the
lexer-side follow-up this needs.
)

${v@Q}, printf %q and declare -p copied valid UTF-8 characters
verbatim in every locale. GNU's ansic_quote multibyte pass-through
(lib/sh/strtrans.c:266-282) and ansic_shouldquote (strtrans.c:
341-361) are the UTF-8-locale branches; under LC_ALL=C every byte
>= 0x80 is non-printing and renders as per-byte octal (café ->
$'caf\303\251'). Gate all three implementations' pass-through on
crate::locale::is_utf8(): parameter_replace's is_ansic_printable
(@Q/%q transforms), arrays/storage's ansic_shouldquote + ansic_quote
(declare -p), and printf's %q decision + char fallbacks.
$'\U80000000' kept the literal escape text under an explicit
non-UTF-8 locale. GNU lib/sh/unicode.c u32cconv reaches wctomb only
for c <= 0x7fffffff and its u32toutf8 length table tops out below
0x80000000, so such values convert to zero bytes in EVERY locale
(strtrans.c:161-181 routes $\'\u/\U\' through the same u32cconv).
Drop values >= 0x80000000 at the top of push_ansi_c_codepoint,
before the rubash#353 locale gate that would otherwise keep them
literal under LC_ALL=C.
GNU shell.c run_startup_files -> maybe_execute_env_file: a non-interactive shell (login shells included, after the profile chain) sources the expanded value of BASH_ENV; a missing file is skipped silently. run_startup_files only ever ran the profile/rc chain, so BASH_ENV was ignored in every shape. New invocation::bash_env_file resolves the variable (expansion, ~, must be an existing regular file); an empty HOME no longer returns early, since GNU sources BASH_ENV with HOME unset.
GNU shell.c:905-911: a lone - or -- ends option processing and the next argv is the script file. The short-option loop only advanced past the marker, so `rubash -- -c 'echo nope'` went on to execute the string; niubash already matched GNU. An options_ended flag now routes every post-marker argv to the operand (script) arm, and the operand arm skips its invalid-option check for such operands (`-- -Z` is a file name, 127).

Note: tests/cli_tests.rs carries 12 probes written against the pre-fix drift form (`rubash -- -c ...` via .arg("--")); under the GNU behavior they need the .arg("--") dropped — the same probes pass without it.
GNU builtins/read.def:911: an OS read error (EBADF on a closed stdin) reports the error and fails WITHOUT binding the names; only a genuine EOF binds the (empty) record. The closed-stdin arm shared the EOF path, so `read x <&-` left x set-but-empty instead of unset. The arm now binds nothing unless a -i prefill supplies the text.
coreutils modechange.c (POSIX omitted-who rule): when no who letters are given, the clause bits are ANDed with ~umask for +, - and = alike (`umask 007; chmod +x f` 0660 -> 0770). apply_chmod_mode now takes the process umask (via __RUBASH_UMASK or a umask peek) and masks omitted-who clauses; explicit who clauses are unchanged.
#1481)

parse.y yyerror: a syntax error discards the whole parse unit being shifted. The completed-command pop only matched commands on the error's physical line, so `if true; then\necho hi; fi junk` kept the if-compound and executed it. The pop now also drops a trailing command that started on an earlier line but ends on the error line (multi-line compound whose closer shares the line).
general.c:843 absolute_program treats / (and \\ under Windows) as the separator. slash_command_execve_error_message counted a backslash on every platform, so `./x\\y` on Linux got the wrong errno wording; the check now mirrors path.rs has_path_separator's cfg!(windows) gate.
…1483)

GNU subst.c:10278 report_error names the word as handed to expand_word_internal: (1) the citation is the WHOLE word, not the ${...} fragment; (2) the $' sigil's dollar is consumed by the lexer, so ${$'x'} is cited as ${'x'}; (3) an unquoted embedded ${$'...'} reaches the same default — the $' decode is the quoted-context extquote path only, so pre${$'x'}post now errors instead of silently decoding.
…#1484)

GNU prompt.c decode_prompt_string: \\s expands to shell_name, which shell.c set_shell_name derives from argv[0]. The renderer hardcoded "bash"; it now reuses the executor's interactive_shell_basename (widened to pub(in crate::executor)).
…ment (#1485)

The unclosed-diagnostics route re-runs recursive prefixes that toggle the quote state per segment, and each nested run printed its own EOF diagnostic (3x for one script). Prefix runs now take diagnostic ownership away from nested runs (suppression flag through run_source_impl); control flow and the single top-level report are unchanged, matching parse.y's single EOF error.
#1486)

builtins/umask.def sets the mask through umask(2), which keeps only mode & 0777 — `umask 7777` must display 0777. The numeric arm now masks to 0o777 inside the <= 0o7777 acceptance range; larger values take the existing octal-range error with the mask unchanged, as GNU does (10000, 12345).
builtins/shopt.def: the -s listing path filters by mode. execute_set_option_mode fell through to the full shopt -o table for -s; the Set mode now prints the -o table filtered to set options (-u already filtered correctly).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Verification status: the lib suite run for this slice is in progress on the shared dev box, which is currently memory-thrashing under ~11 concurrent Rust builds fleet-wide (8 GB RAM, no swap), so builds are crawling at a small fraction of normal speed. The 246-case differential and the paired niubash runtime run are queued behind it (one build at a time). Results will be posted here when they land; baselines for comparison are lib 718/1 (sole failure: the pre-existing root-environment ownership_unary_operators_check_existing_file) and differential failures {gl08, ms10}. No action needed from reviewers — noting this so the wait is not mistaken for a stall in the change itself.

@caomengxuan666
caomengxuan666 merged commit 62e66bb into master Oct 24, 2026
4 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/bulk-r3-slice2 branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment