Repository navigation
fix: round 3 slice 1 — 23 fixes (reopen residuals, hunt batch, rechecks) - #1500
Merged
Merged
Conversation
A pipeline element's here-string word, heredoc body and (on the concurrent external fast path) plain arguments skipped the word-expansion error scan the simple-command path runs, so under set -u 'cat <<< prefix$p | wc -w' silently expanded $p to empty where GNU reports 'p: unbound variable' and kills only the element (redir.c do_redirections runs inside the element's fork, execute_cmd.c:5606/5884; words first via expand_words). - execute_pipeline_stage_inner now runs the same parameter_heredoc_expansion_error gate as the top-level command path, contained to the stage like the existing word gate. - Both concurrent-pipeline admissions decline when a member has a pending expansion error, probed by the new side-effect-free parameter_expansion_error_pending twin of the reporting scan (the reporting scan executes comsub prefix bodies and cannot be run speculatively).
… driver (#1072) script_uses_history only recognized a line-initial 'set ', so the reopen repro 'shopt -s histverify; set -o history; set -H' (and any mid-line set, e.g. after another command) missed admission to the grouped history driver and fell to the whole-file fast path, which does no history processing at all: '!!' stayed literal, nothing was recorded, and histverify never came into play. GNU's reader is incremental (evalstring.c parse_and_execute feeding bashhist.c pre_process_line per line): a set builtin in any command position enables recording/expansion for every later line. Correct the admission predicate's invariant to match: scan each line for the word 'set' at a command boundary (line start, whitespace, ';', '&', '|', '(', '{') and run the existing -o history/histexpand / -H-cluster check on its arguments. Over-admission (a 'set -o history' inside a string) only costs the slower grouped driver, never semantics. Verified against the GNU bash 5.3.20 oracle: the reopen one-liner, split-line forms, either option order, mid-line x=1 prefix, history list contents, and no-history controls all match byte-for-byte; script_driver_history_in_regressions (12) and lib hist tests pass.
…the file (#1161) The --rcfile/profile/BASH_ENV path (run_init_file) executed startup files with a bare whole-file run_source: no sourced-file context and no input name. Three residuals followed (GNU anchor: shell.c run_startup_files sources the files, error.c:300-316 parser_error prefixes with yy_input_name()): - A syntax error in an rcfile reported the invocation's stream name ('bash: -c: line 1:') instead of 'bash: badrc: line 1:' plus the offending-line echo. run_init_file now sets __RUBASH_IN_SOURCE and __RUBASH_SCRIPT_NAME=<file> for the run (restored afterwards), and the gnu_errfmt twins parser_error_prefix / parser_error_prefix_for_line gained the sourced-file suppression of the '-c' segment (with the interactive shell-name prolog) that parser_diagnostic_prefix already had. - A top-level return in a startup file (e.g. /etc/bash.bashrc's '[ -z "$PS1" ] && return' guard) errored 'can only return from a function or sourced script'; with the context set it is legal, and run_source_impl now consumes a Return unwind at a unit top as an ordinary status (evalfile.c source_file) instead of printing a bare 'return N' line through its catch-all error arm. - offending_line_echo_enabled: the echo is suppressed only for the interactive shell's own input stream; a sourced file's line echoes in both modes (oracle: 'bash -i -c source badrc' echoes, a typed bad line does not). Verified byte-for-byte vs GNU bash 5.3.20 (same argv[0]): rcfile syntax error + echo + AFTER runs rc=0, rcfile top-level return stops the file silently, interactive '. badrc' identical, plain -c and script-file shapes unchanged. lib tests 718/1 (same pre-existing ownership-test failure as baseline); startup/source suites green.
…#1058) glibc regcomp treats a quantifier after a quantifier as NESTED (leftmost-longest), but the regex crate reads quantifier+'?' as its lazy marker, so 'a.+?b', 'a*?', '(aa)+?', 'a{2,}?' matched short or empty where GNU matches long. And the empty-minimum intervals 'a{,5}' / 'a{,}' (glibc: {0,5} / {0,}) were rejected outright. - translate_posix_ere_quantifiers (in the =~ compile path, after the existing POSIX translations/gates): a '?' directly following another quantifier wraps the whole repetition in a non-capturing group — 'a+?' -> '(?:a+)?' — preserving capture-group numbering; '{,m}' / '{,}' are emitted as '{0,m}' / '{0,}'. Other stacked operators ('**', '*{2}', '?+', '{2}{2}') already nest identically in both engines and pass through untouched. - posix_ere_has_dangling_quantifier joins the pre-compile gates (glibc REG_BADRPT): a quantifier with no quantifiable operand — pattern/subexpression start, after '|' or '(', or after the '^' anchor ('a^*' invalid; '$' is an operand, '$*a' compiles) — is now a compile error instead of silently matching. - regexp_error_reason maps the dangling case to 'Invalid preceding regular expression' ('*o*', 'a|*b', '(*b)') and an interval with min > max to 'Invalid content of \{\}' ('a{2,1}'), replacing the generic fallback; dangling is checked first ('{2,1}' at pattern start reports BADRPT, as glibc does). The reopen's rc=2 expectations for 'a.+?b' and the empty regex are Android bionic regcomp behavior; on the sanctioned glibc baseline both are legal (nested match / rc=0) and now agree. Verified byte-for-byte vs GNU bash 5.3.20 over a 35-case matrix (match extents, BASH_REMATCH groups, rc, diagnostics); cond/regexp regression suites green.
…ly on terminal delivery (#1034) Round 1 fixed the ^C latency of the builtin 'sleep' fast path by modeling any trapped terminating delivery as 'the real child died': the trap fired immediately. Overshoot (the reopen): a kill(2) addressed to the shell alone — '(sleep 0.5; kill -INT $$) & sleep 10' — leaves GNU's real sleep running, and jobs.c:3064 wait_for defers the trap until the command completes (~10s); rubash fired at ~0.5s. The discriminator is the delivery's origin. The kernel backend now runs on signal-hook's WithOrigin exfiltrator (extended-siginfo) and records, per managed signal, whether the most recently drained delivery was kernel-caused (si_code SI_KERNEL — the terminal driver's group signal for ^C/^\) or sent by a process (kill(2) / the shell's own kill builtin, which also clears the record via note_self_delivery). sleep_interruptibly's virtual-child abort now requires a kernel-caused delivery: terminal ^C still ends the sleep at once (trap runs, 128+sig recorded — pty-verified identical to GNU), while kill(2) deliveries defer to completion exactly like a real external wait (reopen repro and /bin/kill, sender-alive, and real-/bin/sleep variants all ~10s, rc=41, matching GNU). A kill(2) addressed to the whole process group still defers — the queues cannot tell its addressing from a pid-addressed kill; documented in the sleep_interruptibly comment. lib tests 718/1 (same baseline failure set); signal/trap suites green (issue1035_1036's background_compound failure reproduces on the pristine baseline — pre-existing, environment-timing).
GNU trap.c holds signals whose slot has no name (decode_signal == NULL: Linux 32/33, bionic 32..40) in the trap table under the bare number, so `trap '' 32` lists back as `trap -- '' 32` and an entry-ignored hole (initialize_traps snapshot; bionic signal 38 ignored by the Termux launcher) lists as `trap -- '' 38`. normalize_signal returned the empty slot name, keying every hole trap under "", so listings dropped them and `trap -p 38` printed an empty signal name; seed_startup_traps likewise dropped entry-ignored holes. normalize_signal now maps a numeric operand for a hole slot to the number string, and the startup seed folds entry-ignored holes through the same key (entry_ignored_key). Verified against GNU bash 5.3.20: the runtime hole matrix (trap -p 32/65/99, trap '' 32, trap -p) is byte-identical, and the entry-ignored SIGRTMIN+4 matrix is unchanged.
GNU execute_cmd.c:5377 runs the RETURN trap at function exit with the from_return_trap suppression compiled out (#if 0), so a `return` inside the action rethrows through trap.c's return_catch and the trap fires again: `trap 'return 9' RETURN` spins forever in bash 5.3.20 (oracle: timeout kill, no output). rubash absorbed the trap's return once as the function status, ending the script normally. run_function_return_trap now loops: a Return out of the action restarts the fire and becomes the pending return value; when a fire completes, the function returns the LAST thrown status (finite-chain oracle: action returns 9 while n<3 then completes -> rc=9, n=3). The trio regression test is rewritten to that finite chain since an unconditional return can only hang. exit-in-trap and the sourced-file RETURN path are byte-identical to GNU before and after.
A persistent output process substitution bound by bare `exec` (`exec > >(tee -a "$log") 2>&1`, the installIllumioVEN.sh idiom from the #1336 errata) never delivered its stream: the deferred body ran only from close_persistent_output_fd, and nothing reached it when the fd was rebound, when the owning subshell region ended, or when the shell exited — the endpoint was silently overwritten and the carrier input abandoned, losing the whole stream (script exited after its first log line; tee's log was never created). GNU runs the substitution as a real child holding the pipe: EOF — and with it the reader's completion — arrives when the LAST descriptor referring to the pipe closes (subst.c process_substitute; redir.c do_redirections close semantics), including at shell exit and at a subshell fork boundary. Mirror that in the deferred model: - open_persistent_output_process_substitution flushes the previous body before rebinding instead of abandoning it. - execute_stdio_only_exec_redirect flushes the displaced body on every persistent rebind arm (plain file, dup/move, >&word), after the new target is known to succeed so a noclobber failure keeps the substitution alive. - close_persistent_output_fd counts remaining references to the same substitution (carrier path + body source): an intermediate close of a dup'd descriptor drops only its own registration; the body and the carrier teardown wait for the final close. The exit/region sweeps close in descending fd order so fds 1/2 in a dup group close last and the stdio-marker fixup hands the body its stdout/stderr. - restore_flat_subshell flushes the substitutions the region opened (ownership = registration differs from the parent's env) before the parent's env is swapped back; finish_shell sweeps all remaining substitutions after the EXIT trap. Fixes the SYNTAX-REJECT/HANG errata target installIllumioVEN.sh: the script now runs to completion with stdout byte-identical to GNU bash 5.3.20 (one residual: a pre-existing +7 line-number drift in a 'command not found' diagnostic later in the script, unrelated to the stream). The other three errata assets match GNU on this baseline already (load_properties_to_env.sh: no hang reproduces; Cylon.sh: both shells wait in its interactive menu loop; linux_exploit_suggester.sh: byte-identical output). Refs #1336
GNU echo -e decodes \u/\U via ansicstr (builtins/echo.def:169 -> lib/sh/strtrans.c:161-181 -> lib/sh/unicode.c:239 u32cconv); in a non-UTF-8 locale u32cconv falls back to u32tocesc (\u%04X/\U%08X), so under LC_ALL=C the escape stays literal. Apply the same gate the ANSI-C decoder already uses (#353), reading the locale from the executing shell's variable table (GNU sv_lc* watchers make even an unexported LC_ALL assignment count) via a thread-local guard the executor installs around echo.
…the flush (#1489) builtins/hash.def:107-109 sets expunge_hash_table and keeps parsing; hash.def:150-151 flushes the table, then the name loop rehashes each operand (add_hashed_command) or reports 'hash: name: not found' (rc 1). The old early return made 'hash -r name' silently delete a single entry with rc 0. Bare 'hash -r' still clears silently, and the -p-without-name usage error still precedes the flush.
…ormat (#1490) builtins/printf.def:586-614 (case '('): when the scan for the closing paren runs off the format (or the char after ')' is not 'T'), GNU issues builtin_warning "'\0': invalid time format specification" (with the offending char in place of \0 when there is one), prints the '%' (fmt = start; PC(*fmt)), and continues scanning the rest of the directive as ordinary format text — rc stays 0. Rubash reported 'missing format character' with rc 1 for the unterminated shape and printed the raw spec for the not-T shape. Both arms now rescan the directive text through render_one_pass.
…ing (#1491) lib/sh/shmatch.c:58 sh_regmatch surfaces regerror() verbatim after 'invalid regular expression `<pat>': '. glibc regcomp fails a pattern ending in a bare '[' or '[^' with REG_BADPAT ('Invalid regular expression'), while a bracket with any content fails with REG_EBRACK ('Unmatched [, [^, [:, [., or [='). regexp_error_reason mapped every unterminated bracket onto the EBRACK text; split the end-of-pattern shape onto the BADPAT text (both verified against the system regcomp and GNU bash 5.3.20).
variables.c:1873-1874: INIT_DYNAMIC_VAR(HISTCMD) is followed by VSETATTR(v, att_integer), like RANDOM/SRANDOM/BASHPID. dynamic_declaration_view had HISTCMD in the attribute-less group rendering 'declare -- HISTCMD'; move it to the -i group. (OPTIND already carries its integer mark from init, variables.c:611.)
…d lag) (#1494) GNU kill_pid is pure delivery; the shell learns of a stop only in waitchld, whose effect is observably one top-level command late: 'kill -STOP %1' then 'jobs' on the next line still shows Running with the old +/- marks, an intervening command lets Stopped (and the current-job promotion) appear, and same-line '; jobs' never sees it. Rubash's kill path marked the job synchronously. It now records a DeferredJobState stamped with the reader command sequence; refresh_background_jobs applies marks a full command old. Monitor-mode gate from #1247 unchanged.
builtins/read.def:911: a read(2) failure in builtin_read is
builtin_error("%d: read error: %s", fd, strerror(errno)) with
EXECUTION_FAILURE. rubash's fd-table byte reader swallowed the
error as EOF, so 'read x < dir' failed silently. The reader now
records the first hard failure's strerror text (cleared per record
and whenever a fallback transport serves a record), and the read
builtin's no-record chain reports it in GNU's shape.
…1496) builtins/common.c:307 sh_wrerror + :320 sh_chkwrite: a builtin whose stdout flush fails reports 'write error: <strerror>' under its own name (via builtin_error) and returns EXECUTION_FAILURE. Rubash let the io error escape the stage-stream Path target (and echo's direct file arms), so the command boundary printed the bare '<script>: line N: No space left on device' for echo, printf, and the internally emulated /bin/echo alike. Both paths now fold the failure into the sh_chkwrite shape (diag + status 1 + write-failed flag), mirroring the existing Closed-target arm.
…hell (#1493) GNU: '( ulimit -f 0; exec dd ... )' forks a subshell whose image the exec replaces; when dd dies of SIGXFSZ the parent shell's waitchld prints '<pid> File size limit exceeded ( ... )' (jobs.c:4625). Rubash runs the subshell in place and its exec spawn helpers (run_external_exec*) flatten the wait status to 128+signal, discarding the death fact, so no notice was ever queued. The exec builtin now records (pid, signal) for the executor, which — only inside a subshell, since a top-level exec leaves no shell to report in GNU either — queues the standard notice for the reader boundary.
…CARD gates compare in one line space (#1186) The grouped/REPL run_source path rebased token.position and token.column by the group's line_offset but left token.logical_line unshifted. Command.logical_line therefore stayed in the parse-relative space while the evalerror DISCARD gate (eval.c:111 jump_to_top_level(DISCARD)) compares it against reader-line state seeded from offset (absolute) lines. On every interactive line after the first, the comparison missed, the armed failglob discard was cleared instead of applied, and same-line commands after a compound boundary still ran: '{ set -- /no/such/*.zzz; }; echo rc' printed rc in the REPL while the file and source forms were correct. The source builtin's own token shift had the same omission; both sites now shift logical_line with position.
…'/$'\U' values (#1234) push_ansi_c_codepoint ran every char of u32cconv_utf8_text's output through markers::push_literal_char. For a genuine scalar char that is the registry-zone protection $'\uE314' needs, but for non-scalar values (surrogates, > U+10FFFF) and carrier-control values u32cconv_utf8_text returns raw-byte marker pairs — the transport form of GNU unicode.c u32cconv's byte output (strtrans.c:161-181) — and the literal-char loop demoted those pairs to U+E400-prefixed literal PUA text. Only printf's two-layer accessor unwrapped them again; echo and pipeline serialization restored them as literal marker chars, emitting UTF-8 garbage for $'\U00110000' / $'\uD800'. The pairs now go out verbatim, indistinguishable from the \x byte path, so every single-layer decoder restores the same bytes GNU produces. The genuine-scalar path is byte-identical to before.
execute_time_ast_command printed the timing block itself, and the
list loop's ERR-trap adjudication for the timed command only ran
afterwards — 'trap ... ERR; f(){ return 3; }; time f' printed the
real/user/sys block BEFORE the trap action. In GNU the trap fires
inside the inner execute_command (execute_cmd.c execute_time_command
-> execute_command -> run_error_trap) and execute_time_command prints
its report after that returns.
The list-loop time branch now raises defer_list_time_report:
execute_time_ast_command queues (start, posix_format) instead of
printing, and the loop flushes the queue after maybe_run_error_trap
and before the errexit jump (GNU still prints the report for a
set -e-fatal timed command). Unwind exits drop the queue, matching
GNU's jump past the print. Other execute_time_ast_command callers
(pipeline stages, compounds) never raise the flag and print as
before; nested time reports flush in completion order.
Termination notices already ran at the reader boundary, but nothing printed when a background job STARTED: interactive 'sleep 30 &' showed no '[1] <pid>' where GNU 5.3.20 prints it immediately (execute_cmd.c async launch -> jobs.c pretty_print_job). GNU's gate is interactive-only — verified printed with monitor on and off, and never in non-interactive shells, not even with set -m. Both registration sites in execute_background_ast_command (the direct external spawn and the wrapper respawn) now keep the JobId returned by register_process_with_stages and call notify_async_job_started, which writes '[<job>] <pid>' to fd 2 when __RUBASH_INTERACTIVE is set. The coproc registration is a different GNU path (no notice) and is untouched.
The dangling-quantifier gate treated '$' as an operand on the
strength of a probe note claiming '$*a' compiles. Re-verified
against glibc regcomp directly (REG_EXTENDED): '$*a', 'a$*',
'$*' all fail with REG_BADRPT (13), exactly like 'a^*'; GNU bash
5.3.20 agrees (rc=2). Treat '$' like '^' in the scan — an anchor
is never a quantifiable operand — and correct the doc comment.
Quantifiers after groups ('(a$)*') and mid-pattern '$' before a
non-quantifier ('a$b') are unaffected.
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.
Round 3, slice 1 — rolling delivery of the bulk-fix wave: 26 commits (one per issue, plus one integration repair found during verification). Every fix was reproduced and verified against a self-built GNU bash 5.3.20 oracle before landing.
Fixed
Fixes #1034
Fixes #1058
Fixes #1072
Fixes #1106
Fixes #1124
Fixes #1130
Fixes #1161
Fixes #1186
Fixes #1234
Fixes #1256
Fixes #1277
Fixes #1312
Fixes #1325
Fixes #1336
Fixes #1454
Fixes #1488
Fixes #1489
Fixes #1490
Fixes #1491
Fixes #1492
Fixes #1494
Fixes #1495
Fixes #1496
Partial progress (not closed by this PR)
execnow performs a real process-image replacement on Unix (host opt-in); broader coverage still pending.Refs #1109
Refs #1175
Refs #1493