Repository navigation
Bulk fix: 112 GNU bash 5.3 compatibility issues from the 2026-10-22/23 differential audit - #1181
Merged
Merged
Conversation
GNU evalstring.c parse_and_execute on an empty/blank/comment-only string leaves eval_builtin returning EXECUTION_SUCCESS; the executor's execute_eval_source_inner left exit_code untouched when the parsed AST had no commands, so `false; eval ""; echo 0` printed 1. Record no_commands at parse time and force exit_code 0 when the eval'd string ran without error and contained no commands.
execute_set_command's fast paths (apply_simple_set_flags, apply_set_positional_operands, the set -- branch) applied the flags and returned 0 without ever processing cmd's redirections, so `set -- -a -b > o1.txt` created no file and `set -- -b 2>/bad/path` silently masked the open failure. GNU applies do_redirections before the builtin; any set carrying redirects now goes to execute_set, whose write_buffered_builtin_output honors them (file created, failing open reports with rc 1).
…reate (#1025) set -C with a compound command redirected to a NONEXISTENT file failed with 'cannot overwrite existing file': the prepare phase (apply_compound_*_arm / apply_brace_group_redirects / function-call splice, mirroring GNU redir.c do_redirection_internal) creates the target through the noclobber O_EXCL open, and the bind phase (open_compound_output_redirects) then ran the same O_EXCL open again for the fd-table binding, failing on the file the same command had just created. Prepare-phase opens now go through create_redirect_output_prepared, which records the created target in Executor::noclobber_prepared_targets; the bind phase consumes the record exactly once instead of re-opening. Genuinely pre-existing files still fail in the prepare phase, simple commands keep the plain check, and >| / >> are untouched.
…1029) exported_function_command_text hand-joined the quote-stripped expansion values in command.words/assignments, dropping every quote and leaking lexer carrier markers (\037/\021) into BASH_FUNC_<name>%%, so any child re-parsing the value got a corrupted function (x="a b" became x=a b, "$@" became $@). GNU uses print_cmd.c make_command_string for both declare -f and the exportstr; render each body command through crate::parser::ast_print::pretty_print_command, the same printer declare -f uses, which renders from word_metadata/assignment_raws with value re-quoting where no raw survives. Verified round-trips rubash->GNU bash and rubash->rubash, including heredoc bodies.
…/arrayvar/hostname/binding generators - CA_SIGNAL: build from signal_names[] model (pcomplete.c:606 it_init_signals): EXIT first, SIGJUNK(n) for unnamed slots, DEBUG/ERR/RETURN last; no more blank candidates (#1043) - CA_SERVICE: parse /etc/services like getservent via bashline.c:2668 bash_servicename_completion_function: primary name per entry in file order, alias only when name misses (#1044) - CA_VARIABLE: hide __RUBASH_* transport keys and top-level FUNCNAME, add dynamic cells (BASHPID/SECONDS/RANDOM/LINENO/...) per variables.c initialize_dynamic_variables (#1045) - CA_ARRAYVAR: add dynamic GROUPS, drop init-marked FUNCNAME / PIPESTATUS (#1046 companion) - CA_HOSTNAME: snarf_hosts_from_file (bashline.c:795) over HOSTFILE or /etc/hosts, order+duplicates preserved (#1052) - binding list: drop paste-from-clipboard, add vi-bword/vi-eword/ vi-fWord and order the vi block like GNU's funmap (#1052)
GNU names a job by its command name (%sleep), not the full command line (sleep 30 &).
builtins/hash.def:141-144 prints 'hash table empty' only for the plain form; with -l it is suppressed at compat level > 50 (5.3=51).
groups_words() was a stub returning ["0"]. Port GNU general.c:1281 initialize_group_array + variables.c:1637 get_groupset: getgroups() order, primary gid guaranteed present and swapped to element 0, empty set degrades to [gid]. Cached for the process lifetime like GNU's group_set. declare -p GROUPS now renders every element.
…variable (#1050) GNU variables.c:3839 unbind_variable removes the dynamic cell; SECONDS=7 afterwards is a plain static bind (declare -- SECONDS= "7", no ticking). Rubash's dynamic assignment arms (SECONDS/ RANDOM/SRANDOM/BASHPID/BASH_SUBSHELL/FUNCNAME/LINENO/BASH_COMMAND) now stand down when the name carries the UNSET_DYNAMIC_VARS mark so the plain bind lands in the variable table.
… init bottom frame (#1051) execute_cmd.c:5337-5347 execute_function: init_bash_argv + push_args run only in debugging_mode; without extdebug the cells stay empty. Rubash pushed frames on every call, leaking the call stack and desyncing ${#BASH_ARGC[@]} from declare -p. Push/pop are now gated on the extdebug shopt (pop only what the call pushed), and the first materialization installs GNU's bottom frame — the shell's own positional parameters reversed — which persists; top-level extdebug reads synthesize it like get_bashargcv.
…1047) builtins/command.def CDESC_STDPATH: find_user_command walks conf_standard_path() for this command; $PATH is never rebound. Replace the env_vars PATH swap in the re-dispatch with an Executor standard_path_scope consulted by the simple-command execution lookup (on a throwaway env copy), so child environments and nested builtins keep the user's PATH.
builtins/jobs.def disown_builtin: -h is nohup_only — jobs.c:1548 nohup_job sets J_NOHUP and the job stays in the table (jobs lists it, wait %N still resolves). The -h flag was parsed and dropped. DisownAction now carries nohup_only through Current/All/Jobs; JobEntry gains the nohup flag.
shell.c:1007 exit_shell calls maybe_save_shell_history whenever remember_on_history (set -o history) — finish_shell gated the whole save on the interactive flag, so scripts lost it. Also history -w no longer resets lines_this_session: history.def's WFLAG branch (write_history) never touches the counter; only -a (maybe_append_history) consumes it, and GNU's exit append re-appends the -w-written session lines.
GNU execute_cmd.c:6139 shell_execve: execve first; an ENOEXEC text file is executed by the shell itself. std::process::Command spawns via glibc execvp, whose ENOEXEC fallback substitutes /bin/sh before rubash can classify. On unix, classify before spawning: a regular file that is neither #!-headed nor ELF is an execve-ENOEXEC candidate — binary refusals keep their diagnostic, text goes to execute_enoexec_shell_script.
… via the -c wrapper (#1033) execute_background_ast_command already resolves a bg command's redirections into fd 0-2 handles (resolve_background_stdio), but background_direct_external_command rejected ANY redirection, so every redirected job ran under the rubash -c wrapper: $! named the wrapper, kill -TERM killed the wrapper (143) and never reached the job's own traps, orphaning the real work. When every redirect entry was consumed into the stdio triple (the Option mirror fields duplicate that list), the direct spawn carries the whole redirection set — admit it. Unconsumed remainders (fd>2, {fd} vars, procsub, failed opens) still take the wrapper, and unix ENOEXEC candidates stay with the wrapper's shell-fallback classification.
…; trap dispatches immediately (#1034) GNU runs sleep as a real child (jobs.c:3064 wait_for): a group-delivered SIGINT kills the child, wait_for returns, and the shell's INT trap dispatches at once; a shell-only delivery defers the trap until the child completes, and rubash's real-external wait already matches both. The in-process sleep fast path has no child that can die, so a trapped terminating signal sat queued for the sleep's whole remainder (rc correct, seconds late). sleep_interruptibly now treats a pending trapped signal from the kernel-managed terminating set (HUP/INT/QUIT/TERM/USR1/USR2) as the virtual child's death: dispatch pending traps immediately, end the sleep, and report 128+sig as the command status. Trapped non-terminating signals keep GNU's defer-to-completion rule. Also documents why the unix external wait stays a blocking waitpid (wait_for semantics).
…us (#1054) - trap -p with no operands in posix mode lists every canonical signal, untrapped ones as 'trap -- - NAME' (builtins/trap.def display_traps); glibc-reserved slots 32/33 print as bare numbers. - kill -l with no operands in posix mode prints the one-line bare-name list (builtins/kill.def list_signals). - hash with an empty table stays silent in posix mode. - kill %jobspec with no such job in posix mode prints the diagnostic but exits 0. Verified byte-for-byte against GNU bash 5.3.20.
GNU sv_strict_posix (variables.c:6257) -> posix_initialize (general.c:103-128) writes the option variables directly and only calls set_shellopts(); BASHOPTS is a stored variable rebound solely by shopt.def set_bashopts() at startup and on shopt changes. The posix transition walk in 'set -o posix' therefore uses a setter variant that skips the BASHOPTS rebind, while an explicit 'set -o posix' still refreshes SHELLOPTS. Verified: runtime set +/-o posix leaves $BASHOPTS byte-identical to GNU, including the roundtrip inherit_errexit case.
GNU print_var_list is followed by print_func_list; bare set omitted the functions entirely. Append all function definitions sorted by name via the existing write_function_definition.
…#1057) The BASH_FUNC_* environment form now renders simple-command bodies the way print_cmd.c does: '() { cmd1;\n cmd2\n}' — first command on the brace line, later commands separated by ';\n' + one space, closing brace on its own line (byte-verified with od against GNU 5.3.20). Compound bodies still render in source form; porting the full print_cmd.c printer to the env path remains open (see STATUS.md).
…e byte mode (#1058, #1059, #1061) - #1059: store_bash_rematch dropped non-participating captures, leaving groups unset and shifting indices. Every capture group is now stored, unmatched ones set-but-empty (alternation sides included), matching subst.c/execute_cmd.c and the Linux data posted on the issue. - #1058: a backslash-carrying unquoted RHS now reaches regcomp intact (\| \. \+ keep their ERE meaning); (?...) extended groups are rejected with GNU's 'Invalid preceding regular expression' (rc 2); '.' matches newline as under sh_regmatch. Lazy-quantifier and empty-regex sub-cases from the Android filing do not reproduce on Linux glibc (GNU and rubash already agreed). - #1061: in a non-UTF-8 locale the pattern compiles in byte mode (regex::bytes, unicode off) so '.' consumes one byte as glibc regcomp does; byte captures decode back through the raw-byte marker encoding. All verified against GNU bash 5.3.20 (LC_ALL=C and C.utf8 probes).
GNU maps through towupper/towlower — the simple mapping: ß stays ß,
the fi ligature stays, İ lowercases to plain i. Rust's to_uppercase/
to_lowercase apply FULL mappings (ß->SS, İ->i+combining dot), so the
new locale::simple_case_upper/lower keep only single-char results
(ASCII-only in byte locales) and are applied at every casemod site
(^^/,,/~~ patterned and unpatterned, ${v@U/@L/@U}). Verified
byte-for-byte under LC_ALL=C and C.utf8. Updates the part_065 chaining
test, which encoded the old full-mapping behavior.
#1066) GNU forks carry loop_level; a command-substitution body and a SIMPLE pipeline/async element run via parse_and_execute (not execute_in_subshell), so break/continue there are meaningful and end only the child's list, silently, status 0. Boundaries that DO pass execute_in_subshell (execute_cmd.c:1642 resets loop_level) — ( ), compound pipeline elements, coproc bodies — and function calls (execute_cmd.c:5359) reset it and diagnose instead (builtins/break.def check_loop_level). Modelled as inherited_loop_depth on the shell state: comsub and simple pipeline elements inherit (parent loop_depth + inherited), subshell regions / compound stages / function calls clear it, and execute_loop_control validates against own+inherited depth, ending the child list when only inherited depth remains. #1066: 'break 1 2' now takes the fatal channel of builtins/common.c get_numeric_arg — one diagnostic, non-interactive shell exits 2 — instead of a non-fatal status 1 that let the loop continue. Updates cli_tests command_substitution_break_uses_subshell_loop_context, which encoded the pre-fix diagnostic behavior. Verified against GNU 5.3.20 for pipe (both positions), &, { ; }|, ( ), comsub, and function-in-loop forms.
…ded (#1067) subst.c:13219 expand_word_list_internal field-splits an unquoted ${a[@]}/${a[*]} splice and then glob-expands each field. Both for-list routes skipped the glob stage: the quoted-positional segment expander (shared with the argv path, where glob runs downstream) returned final values, and the direct array-at branch split but never globbed. Both now pass through a shared glob_for_list_fields (matches replace the field, no-match keeps the finalized literal, failglob aborts). 'for i in ${arr[@]}' over ('*.sh' 'x') now iterates the matches, like GNU.
The compound-redirect binding forced O_APPEND for every fd-2 file redirect (a model left from rubash#826), so '>f 2>f' shared one append offset and concatenated the streams. GNU redir.c do_redirection_internal gives each >file its own open() with an independent offset; sharing exists only via dup forms (2>&1, &>, >&word — re-verified). Use the redirect's own append flag.
This was referenced Oct 23, 2026
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One branch, one commit per issue (plus three integration commits),
assembled from ten parallel fix clusters rebased onto current master
(7e9dac6). Every fix was reproduced against a GNU bash 5.3.20 oracle
before fixing and re-verified byte-for-byte (stdout/stderr/exit code)
after; the semantics cite the owning GNU C functions in the commit
messages and code comments.
Verification on this branch:
cargo test --lib: 700 passed / 2 failed — identical failing setto pristine master (both are pre-existing environment artifacts of
running as root on a setgid mount; the branch adds 5 passing tests,
no new failures).
pre-audit base; 21 cases fixed, 0 regressed (ps06 flips
run-to-run:
wait -nover two instantly-exiting jobs is a genuinerace; the 3 remaining failures — gl08, ms10, en05 — pre-date this
batch and are untouched by it).
cargo fmt --checkclean (one integration commit applies rustfmtover the cherry-picked series).
Fixes #1013, #1020, #1021, #1025, #1026, #1027, #1029, #1033, #1034,
#1037, #1039, #1043, #1044, #1045, #1046, #1047, #1048, #1049, #1050,
#1051, #1052, #1054, #1055, #1056, #1058, #1059, #1061, #1062, #1063,
#1064, #1065, #1066, #1067, #1068, #1069, #1070, #1071, #1072, #1073,
#1074, #1075, #1076, #1080, #1081, #1082, #1083, #1085, #1086, #1087,
#1088, #1089, #1090, #1091, #1092, #1093, #1101, #1102, #1103, #1112,
#1113, #1114, #1115, #1116, #1117, #1118, #1119, #1123, #1124, #1125,
#1126, #1127, #1128, #1129, #1130, #1132, #1133, #1134, #1135, #1136,
#1137, #1139, #1140, #1141, #1142, #1143, #1144, #1145, #1146, #1147,
#1148, #1149, #1150, #1151, #1153, #1154, #1156, #1157, #1160, #1161, #1162,
#1163, #1164, #1165, #1166, #1167, #1168, #1170, #1171, #1172, #1174,
#1177, #1178
Partially addresses (landed parts are verified; residuals are in the
cluster notes):
BASH_FUNC_name%%env encoding format differs (low) #1057 — exported-function env values byte-exact for simple-commandbodies; compound bodies still render one-line source form.
--pretty-printstdin divergence is fixed;the filed
-csymptom lives in the niubash host (engine alreadymatches GNU).
shopt -s/-ulisting) fixed here; items 1–4are the compat plumbing in fix(compat): converge compat-level plumbing #1173.
needs the compat level threaded into the lexer's brace context.
x86_64 oracle (filed against aarch64-Android GNU).
a read-ahead buffer redesign in fd_table.
spread across the frame/bind path.
-cstring does not prevent earlier commands from executing #1138 — parse-error unit voiding landed in source/eval paths;residual differences are diagnostic-text only.
stderr can still race parent exit (pre-existing pipe/forwarder
architecture, affects all coproc child stderr).
general fragment-freezing interaction remains.
Not in this PR (no code, by design): #1023 (GNU's coproc teardown is
nondeterministic; emulating it risks working multi-coproc support),
#1060 (root cause established — carrier-domain entry-point escaping,
the highest-risk class in this codebase; deferred for a dedicated
full-suite-validated change), #1158 (documented niubash product
design), #1159 (does not reproduce against stock GNU bash — the
filing matches Termux-patched bash), #1175 (exec process-image
replacement needs a host-side opt-in; analysis in the cluster notes).
Issues already fixed upstream or covered by other open PRs (#1094,
#1111, #1122, #1131, #1152, #1155, #1173) are intentionally untouched.