Skip to content

Bulk fix: 118 issues from the 2026-10-23/24 differential hunt (batch 2) - #1498

Merged
caomengxuan666 merged 142 commits into
masterfrom
fix/bulk-2026-10-24
Oct 24, 2026
Merged

caomengxuan666 merged 142 commits into
masterfrom
fix/bulk-2026-10-24

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Second bulk-fix batch: 118 issues fixed, one commit per issue, all verified
against GNU bash 5.3.20 (script-file differential probes; the 246-case
differential suite stays at 244/246 with the same two pre-existing failures
as master, gl08/ms10).

Fixed issues

#1200, #1201, #1202, #1210, #1211, #1212, #1213, #1214, #1215, #1216, #1218, #1222, #1224, #1225, #1227, #1229, #1230, #1231, #1232, #1235, #1236, #1238, #1239, #1240, #1241, #1242, #1243, #1244, #1246, #1247, #1250, #1251, #1252, #1253, #1254, #1255, #1259, #1260, #1261, #1262, #1263, #1265, #1268, #1269, #1270, #1271, #1274, #1275, #1276, #1278, #1280, #1281, #1282, #1283, #1284, #1286, #1287, #1288, #1289, #1292, #1296, #1297, #1298, #1299, #1300, #1301, #1303, #1304, #1306, #1307, #1309, #1310, #1311, #1317, #1318, #1321, #1322, #1323, #1326, #1327, #1328, #1329, #1330, #1331, #1332, #1333, #1334, #1338, #1339, #1340, #1341, #1342, #1343, #1344, #1346, #1347, #1348, #1349, #1350, #1351, #1352, #1353, #1354, #1372, #1373, #1393, #1408, #1409, #1411, #1412, #1413, #1415, #1416, #1417, #1419, #1421, #1422, #1423

Partially addressed (not auto-closed)

Notes

Auto-close keywords

Fixes #1200
Fixes #1201
Fixes #1202
Fixes #1210
Fixes #1211
Fixes #1212
Fixes #1213
Fixes #1214
Fixes #1215
Fixes #1216
Fixes #1218
Fixes #1222
Fixes #1224
Fixes #1225
Fixes #1227
Fixes #1229
Fixes #1230
Fixes #1231
Fixes #1232
Fixes #1235
Fixes #1236
Fixes #1238
Fixes #1239
Fixes #1240
Fixes #1241
Fixes #1242
Fixes #1243
Fixes #1244
Fixes #1246
Fixes #1247
Fixes #1250
Fixes #1251
Fixes #1252
Fixes #1253
Fixes #1254
Fixes #1255
Fixes #1259
Fixes #1260
Fixes #1261
Fixes #1262
Fixes #1263
Fixes #1265
Fixes #1268
Fixes #1269
Fixes #1270
Fixes #1271
Fixes #1274
Fixes #1275
Fixes #1276
Fixes #1278
Fixes #1280
Fixes #1281
Fixes #1282
Fixes #1283
Fixes #1284
Fixes #1286
Fixes #1287
Fixes #1288
Fixes #1289
Fixes #1292
Fixes #1296
Fixes #1297
Fixes #1298
Fixes #1299
Fixes #1300
Fixes #1301
Fixes #1303
Fixes #1304
Fixes #1306
Fixes #1307
Fixes #1309
Fixes #1310
Fixes #1311
Fixes #1317
Fixes #1318
Fixes #1321
Fixes #1322
Fixes #1323
Fixes #1326
Fixes #1327
Fixes #1328
Fixes #1329
Fixes #1330
Fixes #1331
Fixes #1332
Fixes #1333
Fixes #1334
Fixes #1338
Fixes #1339
Fixes #1340
Fixes #1341
Fixes #1342
Fixes #1343
Fixes #1344
Fixes #1346
Fixes #1347
Fixes #1348
Fixes #1349
Fixes #1350
Fixes #1351
Fixes #1352
Fixes #1353
Fixes #1354
Fixes #1372
Fixes #1373
Fixes #1393
Fixes #1408
Fixes #1409
Fixes #1411
Fixes #1412
Fixes #1413
Fixes #1415
Fixes #1416
Fixes #1417
Fixes #1419
Fixes #1421
Fixes #1422
Fixes #1423

…rk UID/EUID/PPID integer (#1184)

Finding 1: the lexer '2' arm finished non-redirect words with a raw slice, skipping dequote — '2$'x'' stayed literal. Route through finish_word_token (parse.y read_token_word: io-number only when the token ends at < or >).
Finding 2: setattr print_readonly/print_exported wrapped values in literal double quotes with raw control bytes; use the declare -p display rule (setattr.def show_var_attributes: ansic_shouldquote -> ansic_quote, else sh_double_quote).
Finding 3: UID/EUID/PPID were marked readonly only; GNU variables.c creates them V_INTEGER|V_READONLY, so declare -p now reports -ir.
Findings 4/6 (procsub diagnostic attribution, nested-backquote EOF quote char in captain-exclusive lexer/continuation.rs) and finding 5 (already fixed by #1151) are documented in the cluster report.
…ine (#1186)

GNU execute_cmd.c reader_loop: an evalerror (parse_bounce FAILGLOB) discards input until end of the failing command's logical line. The grouped history driver split one logical line into several groups, so the tail of the line still ran; the whole-file reader was already correct. Track the discarded line span in run_script_grouped_at_line_offset and skip groups starting inside it. Partial: a brace-group tail of the same logical line can still lose the flag inside the group executor — see cluster report.

NOTE: this commit also carries the #1216 change (same file, initialize_interactive_history: default HISTFILE to ~/.bash_history when unset — GNU variables.c predefines it; without it an interactive session neither loaded nor saved history). It could not be split out cleanly with git add -p hunk merging; the code is the last hunk of this commit's script_driver.rs diff.
printf.def: the \c stop in %b (and in a plain format) terminates the builtin without setting an error status; only real conversion errors fail. The render stop branches forced EXECUTION_FAILURE.
test.def cond_term: a terminating expansion error under -u raises a fatal that unwinds with EX_EVALERROR semantics — the fatal's own status wins even when the folded -z/-n verdict is 0. The conditional wrapper hardcoded exit_code = 1 on that path and discarded the parked fatal status; carry it on the executor and restore it before unwinding.
…1202)

The indexed-subscript reporter wrote straight to the process stderr, bypassing the command's fd table, so 'test -v a[1:2] 2>file' lost the diagnostic. While executing the test/[ builtin's words, capture that reporter thread-locally and flush through write_buffered_builtin_output, which honors the current fd-2 binding. Expansion-time errors outside the builtin keep the raw path, matching GNU.
lib/readline/history.c history_delete: a single offset of 0 names no entry (offsets count from 1); only range endpoints may be 0. The single-offset arm parsed '-0'/'0' as entry 0 and silently succeeded; reject 0 there so the existing out-of-range diagnostic fires.
fc.def echo_input_at_read writes the edited command to stderr as bound by the fc command's own redirects. The echo was a raw eprintln before the redirect scope (and the scope's re-open truncated anything written early); build it as bytes and write it through the fd table inside with_compound_output_redirects, before executing.
execute_cmd.c time_command: user/system come from getrusage(RUSAGE_SELF)+getrusage(RUSAGE_CHILDREN) deltas around the timed command. TimeCommandMetrics hardcoded cpu fields to zero (a documented placeholder); capture the counters at time_command_started and diff them in from_start.
…1213)

builtins/return.def return_builtin: too many arguments is the no_args class — print 'return: too many arguments', status 2, and the evaluation aborts, discarding the rest of the caller's line and unwinding through source. rubash printed the message but kept executing (and gave the top level the wrong diagnostic); route through the evalerror/toomany vehicle exit already uses. The numeric-argument error path is unchanged (BREAK-style containment).
hash.def hash_builtin: find_shell_builtin/find_shell_function matches are a silent no-op (rc 0, no entry), so only external commands enter the table and only they can be 'not found'. Pass the builtin+function name set into execute_with_io and skip those names.
parse.y / readline loop: PS0 is expanded (decode_prompt_string, execute_cmd.c expand_prompt_string) and written to stderr after a complete command is read and before it executes — including the exit command; blank lines print nothing. The interactive paths never rendered PS0; emit it in the accept_line completion branch.
…mmand (#1218)

parse.y time_command grammar: under posix mode the time keyword only applies when the next token is not a -flag word; otherwise 'time' is an ordinary command name resolved through PATH. Gate every keyword-classification site (compound exec, pipelines, command substitution, the simple-command time node) on posix_time_dash_word and rebuild a plain command at execution so the external dispatch (and its 127) applies.
jobs.c wait_for: pids handed out by the shell stay in the bgpids knowledge (GNU waits for them with status 0 and no diagnostic even after disown). Record pids at the real disown sites (never for 'disown -h') and let plain 'wait <pid>' operands that are known-disowned succeed silently; wait -n semantics are unchanged.
jobs/BASH_COMMAND 的命令显示中,无名 coproc 应按 GNU 显示默认名
COPROC(execute_cmd.c 的 coproc 命名、print_cmd.c 的打印);此前
名字被丢弃,显示为 `coproc { ...; }`。

fd 对分配改为 GNU sh_openpipe 模型:四条管道端按 rpipe[0]、
rpipe[1]、wpipe[0]、wpipe[1] 顺序经 move_to_high_fd(general.c)
移到 64 以下最大的空闲 fd,父进程保留 rpipe[0] 与 wpipe[1]。
此前的“固定 63/60、占用则取最低空位”使第二个 coproc 的读端落到
10(GNU 为 62/58)。

回归:tests/regression golden fixture issue1224-coproc-fds
(golden 由 GNU bash 5.3.20 采集)。
GNU variables.c convert_var_to_assoc / arrayfunc.c
convert_var_to_array:已有标量单元(哪怕已赋空值)在转换时成为
元素 [0];没有单元则保持未设置。此前 assign.rs 有一条按变量名
特判的桥接,把空值替换成虚构的复合值(值被编造/丢失);attrs.rs
的 assoc 转换又跳过了空标量,且缺少对应的索引数组转换。

删除按名桥接,让真实复合赋值路径工作;apply_declare_attrs 中
assoc 转换改为:已有非 storage 标量单元(包括空串)即转换,并
镜像补上索引数组转换(format_indexed_array_storage)。

回归:golden fixture issue1225-declare-convert。
GNU execute_cmd.c shell_execve 把用户键入的命令词原样作为
argv[0] 交给 execve;std::process::Command 默认用解析出的程序
路径。于是 `hash -p /bin/dash mydash; mydash -c 'echo $0'` 打印
/bin/dash(GNU 为 mydash),所有普通外部命令的 $0 也都是全路径。

在 external_command_for_named_program 的 plain 分支对 unix 设置
arg0(command_name)(所有调用点传的都是键入词)。同时把 sh/bash
-c 的“追加名字作 $0 操作数”hack 限定到非 unix:unix 上 argv[0]
已承载名字,追加的操作数会盖住 exec -a 的显式 argv[0]
(见 #1227)。
两个根因叠加:(1) exec 的 spawn 构造把解析后程序的 file_stem
当作 command_name 传给 external_command_for_named_program,
`exec /usr/bin/bash -c ...` 的 $0 因此变成 bash 而非键入的
/usr/bin/bash;(2) path.rs 的 sh/bash -c 追加名字操作数在 unix
上盖住了 -a 指定的 argv[0](已在 #1231 的提交中限定为非 unix)。

execute_impl 把键入的命令词经 run_external_exec /
run_external_exec_with_stdio / external_exec_process 穿线到
external_command_for_named_program;无 -a/-l 时 argv[0] 即键入
词(shell_execve),有 -a 时由既有的 arg0 覆盖获胜。

回归:golden fixture issue1227-argv0(与 #1231 共用)。
注:该 fixture 不含 `exec -l dash` 情形——它还受另一个独立根因
影响:rubash 把 BASH 误标为导出变量(declare -x BASH),dash
登录 shell 读 /etc/profile 时因此误入 bash 分支;与本条无关,
另行记录。
GNU 每个内建的 getopt 表都把选项位置的 --help 映射到
CASE_HELPOPT:长帮助打印到 stdout、返回 EX_USAGE(2)。此前
source/eval/command/builtin/type/hash/exec 把 --help 当非法
选项报 usage 到 stderr(printf 已正确)。

逐个接入 builtins::help::print_builtin_help:
- exec:parse_options 在选项位置识别 --help(-- 之后或被 -a
  消费时是数据),execute_impl 打印后返回 EX_BADUSAGE;
- command/type/hash:在各自选项循环的选项位置识别(type 的
  执行器实现与 builtins 实现两处都改);
- eval:execute_with_io 增加 stdout 通道,执行器侧经缓冲输出
  路由(重定向生效);
- builtin:在 `--` 剥离之前识别(`builtin -- --help` 仍是把
  --help 当内建名执行);
- source:解析新增 HelpRequested,impl 经新增的 stdout 通道
  打印(按调用名在 "source"/"." 话题间选择),执行器调用点把
  stdout 缓冲一并走 write_buffered_builtin_output。

回归:golden fixture issue1229-builtin-help。
GNU 中裸 exec 的重定向在选项解析期间处于可撤销作用域
(redir.c do_redirections 的 undo 机制):诊断写进重定向目标,
但 exec 以 EX_BADUSAGE 失败时重定向被撤销,shell 保持原
stdout/stderr。此前 execute_exec 的无操作数分支先把重定向
持久应用再跑内建,`exec --help >f` 后续输出全部被吞进 f。

进入该分支前快照 env_vars 与 fd_table,缓冲输出仍在临时
重定向生效时路由(诊断属于目标文件),状态为 2 时恢复快照。
仅重定向且选项解析成功的裸 exec(上方分支)仍按 GNU 持久化。

回归:golden fixture issue1230-exec-redirect-undo。
GNU tilde.c:裸 ~+/~- 取 $PWD/$OLDPWD(未设置则保留字面);
~+N 按目录栈自左索引(当前目录为 0 号)、~-N 自右索引,
越界保留字面;可带 / 或 : 尾。此前只有裸 ~+/~- 与 ~-1 等
个别形式工作,~+/x、~-/x、~+1 全部原样输出。

新增 expand_pwd_tilde 按 GNU 语义实现(栈经 pushd 的
load_stack 读取),接入 expand_word_prefix 与赋值段的
expand_tilde_segment;复合赋值的元素经同一路径覆盖。

回归:golden fixture issue1232-tilde-pwd。
GNU redir.c:r_move 在命令期间把源 fd 的描述移到目标并关闭
源;命令结束时是否恢复源,取决于 add_undo_redirect——只有
目标在应用时是打开的(fcntl(redirector) != -1)才登记源的
保存/恢复;目标是关闭的时不登记,关闭在命令后依然生效。
此前 rubash 的按命令状态图把 move 当普通复制,关闭从不
持久:`echo two 5>&3-`(fd5 关闭)之后 fd3 仍开着。

apply_ordered_output_redirects 的 DuplicateOutput 臂按此
模型重写:插入目标前先判目标开闭;move 时状态图中源记为
Closed;仅当处于内建缓冲路由(persist_move_closes,本 shell
内执行的内建)且目标原为关闭时,才经 close_persistent_
output_fd + fd_closed_key 把关闭落盘。探针/诊断走查与流水线
stage 路由不置该标志(状态会被丢弃或属于子 shell)。
同臂一并处理自 dup/自 move 的 no-op(详见 #1236)。

回归:golden fixture issue1235-fd-move。
GNU redir.c do_redirection_internal 的 r_duplicating/r_move
应用整体被 `redir_fd != redirector` 守卫:自 dup/自 move
根本不执行 dup2——fd 关闭时也成功,打开时自 move 也绝不
关闭它。此前各应用点要么在验证层以 Bad file descriptor
拒绝关闭 fd 的自 dup(`echo hi 99>&99`),要么先复制再关闭
把 fd 关掉(`exec 8>&8-`)。

统一补守卫:redirection.rs 验证层数字形与词形两处(自引用
时 opened 记账保持不变,后续同表 dup 仍按真实开闭判定);
trap_exec 持久 exec 应用的四个 dup 臂(输出/输入,含关闭
fd 自 dup 不再误报);command_input_scope 的 compound 输入
臂、输出臂与 compound_output_dup_bad_fd 预检;
external_redirects 的子进程 slot 解析(自 move 不再摘除
目标 slot,自 dup 不再因源关闭而整路 decline)。
按命令状态图的自引用处理在 #1235 的 DuplicateOutput 臂中。

回归:golden fixture issue1235-fd-move(含自 dup/自 move 用例)。
1) <> 探针把 path_error 的 "{target}: {err}" 文本又拼了一次
target 前缀,报成 "file: file: ..."。改为与 Input 探针一致
直接透传(redirection_error 消费 path_error 文本)。

2) /dev/tcp 连接被拒时 GNU netopen 先以 sys_error 打一行
"{脚本名}: connect: Connection refused"(无行号段),再由
redirection_error 打 "{target}: Connection refused"。
open_net_redirect_raw 在 ConnectionRefused 时补首行
(script_name_prefix 家族,与 cannot duplicate fd 同源)。

3) 服务名端口:GNU 经 getaddrinfo/getservbyname 解析。此前
非数字端口一律 Invalid argument 且无首行。现在先查
/etc/services(按 tcp/udp 区分),查不到时补首行
"{error_prefix}{port}: Servname not supported for
ai_socktype"(glibc gai_strerror 的 EAI_SERVICE 文本)再
返回 Invalid argument;纯数字溢出按解析器的 16 位截断处理。

已知限制(本提交未覆盖):(a) 上述首行直写进程 stderr,
当失败命令自身带 2>&1 时不随 fd2 改绑进入合并流(第二行
redirection_error 本身会);(b) issue 的 item 4(管道内
写错误诊断与后续命令输出的交错顺序)根因在 stage 延迟
诊断的合并粒度,未在本条处理。

回归:golden fixture issue1237-net-redir。
`((ro++))`(ro 为只读)此前输出两行:正确的
"ro: readonly variable" 之外还多一条伪造的语法错误行。
根源:求值器在 readonly 绑定失败时留下 marker 并由
report_arithmetic_readonly_error 打印真诊断,但
eval_mutable_arith_result 随后又合成一条 "operand
expected" 记录,(( ))/let 的报告器把它当真错误打出。

ShellState 新增 arithmetic_readonly_error 标记:
report_arithmetic_readonly_error 打印时置位;
execute_arithmetic_command / execute_let 入口清零;
report_arithmetic_error_raw_display 与
report_let_arithmetic_error 在置位时跳过合成错误(与
#1150 的 nounset 守卫同形);eval_mutable_arith_result 在
env 含 readonly marker 时不再合成 operand-expected。
GNU 对绑定失败只产生这一条诊断(expr.c 的 evalerror 不
在此路径触发)。

回归:golden fixture issue1238-arith-diag(与 #1239 共用)。
GNU 中无任何元素的关联数组对 nounset 而言等于未设置
(variables.c:元素存在之前变量无值):`((h[k]++))`、
`((h[k]+=1))`、`$((h[k]))` 都报 "h: unbound variable",
而纯赋值 `((h[k]=5))` 是写操作、合法。此前的 nounset
预扫描 arithmetic_unbound_variable 无条件跳过 assoc
下标,永远不触发。

在 ASSOC_VARS 分支补判:跳过下标后若不是纯 `=` 赋值
(新增 arithmetic_subscript_is_pure_assignment:允许
空白、排除 `==`;op 赋值与 ++/-- 都是读),且该 assoc
无元素(assoc_entries 为空,含无条目),返回变量名触发
陷阱。三个调用点((( ))、$(())、let)共用此扫描,一处
修复全覆盖;非空 assoc 缺键、空索引数组在 GNU 中同样
不触发,保持原样。

回归:golden fixture issue1238-arith-diag(与 #1238 共用)。
注:参数展开路径的 `${h[k]}` 在 GNU 报 "h[k]: unbound
variable"(subst.c 另一路径),不在本条范围。
GNU builtins/let.def reports a missing expression as a full line,
'let: expression expected\n'; rubash wrote the diagnostic without the
newline, gluing the next prompt or diagnostic onto the same line.
Add the '\n' and a golden fixture (let-bare-diagnostic) pinning the
stderr bytes against GNU bash 5.3.20.
The comsub fast path answered 'umask' from a canned env lookup and
ignored the arguments: '$(umask -S)' printed the octal mask and
'$(umask 077)' set nothing. GNU subst.c command_substitute forks and
runs the real builtin (builtins/umask.def). Mirror the ulimit branch
below: run builtins::umask::execute_with_io on a cloned env, route its
stderr out, record its status, and snapshot/restore the process umask
on unix so a set inside the substitution cannot leak into the parent.
Golden fixture umask-comsub pins the shapes against GNU 5.3.20.
GNU variables.c bind_variable: a value bound to a cell carrying both
att_integer and att_nameref is arithmetic-evaluated first, and the
numeric result is never a valid nameref target, so
'v=42; declare -in ref2=v' fails SILENTLY with status 1 and creates
nothing. Rubash already skipped the creation (the 5.2.21 husk rule) but
left the builtin status at success, so a following '$?' read 0.
Set attr_status to EXECUTION_FAILURE on that path. Golden fixture
declare-integer-nameref pins it against GNU 5.3.20.
A non-monitor shell never learns that a background job stopped: GNU
notices stops only through waitchld's WUNTRACED report under job
control (jobs.c / nojobs.c), so after 'set +m; sleep 100 & kill -STOP
$!' GNU 'jobs' still shows Running. Rubash has no WUNTRACED poller;
the kill builtin's own mark_stopped/mark_running calls are its only
stop detector, and they fired unconditionally, so the same script
showed Stopped. Gate both marks on the monitor option.
POSIX leaves // implementation-defined and GNU bash preserves it
through logical normalization: cd //tmp binds PWD=//tmp, the prefix
acts as its own root (cd .. yields //), and pwd -P keeps it too. Both
of rubash's normalizers erased it — Path::components collapses // to /
for the PWD string, and getcwd collapses it for pwd -P. Re-apply the
prefix from the raw combined text in logical_destination_display, and
restore it in pwd's physical mode when $PWD names the same directory.
On Windows the prefix is the UNC root from the original filing.
… reap (#1411)

The tracked-kill loop synchronously marked a jobspec-targeted job
completed and removed it from the table for DONT_REPORT signals, so
`kill %1; jobs` listed nothing. GNU kill_builtin only delivers the
signal: the entry stays listed until the reap boundary, which records
the real exit status (preserving the #737 `wait $!` = 143 contract)
and applies jobs.c's DONT_REPORT notice suppression there
(report_pending_signal_notices, the #796 contract). Drop the
synchronous mark/close/remove and the now-dead
jobspec_death_is_unreported helper. The part_036 test that pinned the
empty listing cited a GNU probe that does not reproduce on GNU
5.3.20 — the oracle lists the job on the exact script — so its
expectation is rewritten to the measured contract (entry listed, no
notice, bare wait returns 0).
bg resolved a bare operand as a PID, so `bg $!` resumed (or claimed
to bg) a job GNU refuses to touch. GNU fg_bg.def/jobs.c: an operand
without a leading % draws `warning: {op}: job specification requires
leading '%'` and is then resolved AS a jobspec — `bg 1` selects job
1, `bg sleep` matches by name, and a bare pid matches nothing
(`no such job`, rc 1). Add resolve_fg_bg_operand implementing that
rule after the existing no-job-control gate (which GNU also reports
first) and route bg through it. wait/disown/kill keep the pid reading
of bare numbers.
Same GNU fg_bg.def rule as bg (#1408): `fg $!` used to foreground
and block on a job selected by pid; GNU warns `job specification
requires leading '%'`, resolves the operand as a jobspec, and a bare
pid therefore reports `no such job` with rc 1 without touching the
job. Route fg through the resolve_fg_bg_operand helper added for bg.
GNU redir.c: '>' /dev/fd/N 是 r_output_direction 文件名打开 (find_fd_varname/
r_instruction), 只有 '>&N' 才是 r_duplicating_output 的 dup2。基线在
apply_ordered_output_redirects 的 Output 臂用 redirect_target_fd 预检把
/dev/fd/1 误判为 dup, 且 open_command_output_target 对 File/Stdout/
Stderr 端点一律 clone 共享偏移。修复: (1) 预检增加 dev_stdio_target_
reopens_disk 门 (源 fd 在 fd_table 中绑定普通磁盘文件且非管道 staging
时不走 dup 捷径); (2) open_command_output_target 的 dev_stdio 臂对
File 端点按其路径、Stdout/Stderr 端点按 /proc/self/fd 解析出的磁盘
路径以新句柄重开 (truncate/append 依 redirect), 独立偏移。管道/comsub/
fd2 等 dup 语义不变。实测与 GNU bash 5.3.20 字节一致: 'echo hi >
/dev/fd/1' 产生 hi\n+3 NUL+after、'>>' 追加形、短式与 /dev/stdout/
stderr 变体。
GNU execute_cmd.c: 'builtin exec' / 'command exec' 中 exec 是普通内建
调用 (maybe_make_export_env 之外的 builtin 执行路径), 其重定向遵循
内建的临时重定向语义 (do_redirections 的 RX_UNDOABLE 在内建返回后
撤销), 不进入 exec 的持久替换语义。基线把 'builtin exec >f' 当作裸
exec 持久绑定 fd。修复: 新增 Executor::builtin_wrapper_depth, 在
builtin_direct_command 的 exec/command 臂递增; execute_exec 的两个
无操作数 stdio-only 重定向点改走 execute_stdio_only_exec_redirect_
scoped — 快照 fd_table 与重定向涉及的 fd/fd_var env 项, 走持久路径
应用后恢复, 于是 'builtin exec >f' 只创建/截断文件、本次无输出可写,
后续输出与 fd 3 等编号 fd 均不受影响; 裸 exec 与 'command exec' 的
既有语义按基线保持 (command 前缀递增同一深度, 其下 exec 同样一次性)。
GNU coreutils mkdir 无 -p 时单个 mkdir(2) 失败即报错, 且内建/模拟外
部命令的诊断应服从命令自身的重定向 (本仓的 buffered builtin 输出通
道)。基线 mkdir 一律 create_dir_all (掩盖 ENOENT 父目录错误), 且诊
断用固定前缀直写, 绕过 '>f 2>&1' 的缓冲合并; chmod 三处 eprintln!
同样直写真实 stderr。修复: mkdir 跟踪 -p/--parents (含仅由 pvm 组
成的短选项捆绑与 -m 模式待定), 无 -p 用 fs::create_dir, 有 -p 才
create_dir_all; mkdir/chmod 诊断改走与 stdout 相同的缓冲写入并经
write_buffered_builtin_output 冲刷, 文案对齐 GNU (mkdir: cannot
create directory 'X': No such file or directory / chmod: cannot
access 'X': ...), rc=1。
GNU subst.c string_list/quote removal 对 case pattern 的处理: 带引号
的 "${a[@]}" 多元素时只保留首元素与前导文本拼接, 其后所有内容
(包含后续段) 丢弃; 单元素完全拼接; 零元素不贡献。基线在
quote_aware_case_pattern 中把全部元素拼入模式, 导致多元素模式串错
位 (误匹配/漏匹配)。修复: expand_case_pattern 预扫原文构造
case_pattern_array_at_map (关联数组取本引擎 hash 顺序、索引数组取
下标顺序 — 与引擎自身 [@] 展开顺序一致), quote_aware_case_pattern
的双引号分支改走 case_pattern_quoted_segment 实现首字段规则
(多元素返回 Finished 截断后续段)。7 项对照探针与 GNU 5.3.20 全部
一致 (ALL/NO2/ALL3/N-y/M1/N2/M5)。
GNU parse.y: 赋值词后的 '(' 等复合起始符只有在值本身构成合法赋值
词时才可能继续, 而 extglob 关闭时 '@(' 使值不是合法简单词, 解析在
'(' 处以 syntax error 终止 (rc=2); 先前的 #452 语料结论有误。用
GNU 5.3.20 脚本文件复测确认: extglob 关时 x=@(a|b)、x=1 (echo)、
if/while/for/case 等 7 形全部 rc=2 且错误定位与 GNU 同形; extglob
开时整串是单赋值词、字面值。修复: 从 command_allows_compound_start
移除 command_has_assignment_prefix 豁免并删除其两个专用谓词、
push_compound_command 的赋值合并分支, 使前缀赋值后出现复合命令按
普通语法错误处理; tests/assign_prefix_subshell_regressions.rs 按
实测契约重写 (拒绝形 + extglob 文件形 + 保留真实错误用例)。
GNU parse.y cond 词法: 数字串紧跟 < > 时词法为 IO_NUMBER (在条件
命令中非法), cond_error 报 unexpected token `DIGITS' in conditional
command, near 为数字+单个算符字符 (error_token_from_text 6772);
& / | 是断裂字符, 报告的令牌从算符本身开始 (near 向前越非断裂字符
合并, 不能向后越过算符)。基线把粘连片段整段上报 (1<4→令牌 4、
5&3]]→令牌 &3]]、a&b→near a&b)。修复三处: (1) cond_term 的
post-primary 错误臂增加 io_number_cond_fail: 主词为未引用
DIGITS+[<>]+ 时改报 IO_NUMBER 形 (消息用数字、near 用
CondOffending::Fixed 携带 数字+首算符); 同臂把 & / | 前导的肇事
片段令牌文本截为单个字符; (2) walk_back_near_token: 肇事项以单个
& 或 | 开头时不向前合并粘连片段; (3) walk_back 结果剥掉粘连在
末片段上的 ]] 闭合符。11 项探针 (含 1<<4、12<、5&3]]、-n x&y、
|| 后 1<4) 与 GNU 5.3.20 字节一致, 合法 [[ ]] 与其他错误形
(=~ 未闭合、(a 等) 无回归。
test_kill_background_jobspec_removes_job 与
test_kill_current_jobspec_uses_last_background_job 编码了与
test_kill_jobspec_keeps_job_listed_until_reap 相同的旧前提
(kill %1 后 jobs 立即为空)。GNU 5.3.20 对同一脚本实测: 条目
保留到收割边界 (jobs 列出 Running, 延迟后为 Terminated 列示、
无完成通知)。前者更名为 ..._keeps_job_until_reap, 两者断言
改为 kill:0 + 作业行仍列示; 同步修正 keeps-listed 测试上方
#796 注释的旧结论。
jobs 行的 & 后缀只在作业仍运行时出现; 收割先落时行文为
Exit 143 且无 &, 断言要求 'while true; do true; done &'
整串导致竞速闪烁。改为只要求作业行文本 (状态词不限)。
GNU builtins/read.def skips NUL bytes as the record is read: they
never reach the assigned values or the IFS splitting (printf
'a\0b\n' | read -r v binds "ab"). Strip NULs at the
read_input_for_command funnel and at the read_stdin_until fallback
arm that bypasses it. A NUL delimiter stops the record before any
NUL can appear, so read -d '' is unchanged. GNU-golden fixture
added.
GNU builtins/setattr.def rejects every export/readonly
name[sub]=value operand as not a valid identifier, quoting the raw
subscript and never evaluating it (declare/local/typeset are the
builtins that evaluate). Skip the operand-subscript rewrite for
export/readonly so the evaluated form (a[2]=Q) and arithmetic side
effects (a[i++] incrementing i) cannot leak; setattr's identifier
validation then reports the verbatim operand. The diagnostic's
'=value' suffix is rubash#1347's layer. GNU-golden fixture added
(pins state: rc, no side effect, array unchanged).
GNU cond.c cond_expand_word -> expand_word: a non-fatal expansion
error in a conditional operand (substring expression < 0, bad
substitution) is expand_wdesc_error -> DISCARD, exactly as in a
simple command. rubash's expand_conditional_word only handled the
nounset/FATAL class and silently ignored status-1 errors, so
[[ \ == \ ]] evaluated with the error swallowed and exit
0. Print the diagnostic, record the status in the new
conditional_expansion_error_status cell, stop expanding further
operands, and convert the recorded status into ExpansionFailure
once the conditional finishes and its redirects are restored.
GNU-golden fixture added.
A pipeline element runs in a subshell: a return raised by the
element body ends the ELEMENT with that status, and the enclosing
function keeps running (GNU: f() { { return 3; } | cat; echo
after; }). The compound/function/builtin stage status matches in
pipeline_stages.rs converted ExitCode/ExpansionFailure/BrokenPipe
but let ExecuteError::Return fall through to return Err(..),
unwinding the enclosing function and skipping the rest of its
body. Convert Return(code) to the stage status in all three
matches, mirroring the subshell boundary in ast_exec. lastpipe
stages run in the current shell and are untouched. GNU-golden
fixture added.
Not reproduced on current master (31e2638): diff <(echo a) <(echo
a), cat <(echo hello) and wc -c <(echo 12345) all match GNU bash
5.3.20 — the Unix dev-fd attach in dev_fd_operands.rs already
covers the external-command operand path this 2025-10-05 report
targeted. Add the GNU-golden fixture so the behavior stays pinned;
no code change.
…t names

braced_name_is_bad_substitution computed bytes.len() - 2 unconditionally,
which underflows (debug panic) for the valid one-byte names the gate's own
unit test feeds it ("#", ""). The k5 branch never ran the lib suite on
its final tree, so the failure shipped with #1287; caught by the
integration failure-set comparison against pristine master.
… pre-scan

The k5 fix admitted the ANSI-C literal length operand in the expansion
gate and in the length dispatcher, but the parameter_errors pre-scan
(is_valid_length_parameter_name) still rejected it, so the form failed
end to end on the k5 branch as well (verified). Admit a complete
$'...' literal there too; sibling forms ($"...", '...') stay bad
substitutions, matching GNU bash 5.3.20.
…sorb

The brace dispatch's ExpansionFailure arm absorbed the failure at the
DISCARD boundary (status recorded, rest of the line skipped) but then
fell through to the simple/execution dispatches, which re-ran the
group through execute_command. With the DISCARD armed (rubash#1318's
raise_assignment_discard, and the evalerror arming generally), the
re-run's body list silently skipped the failing line and completed
with status 0, clobbering the recorded failure: '{ z=1; }' on its own
line left $? = 0 for the next line, and a same-line group left the
shell exit status 0 (GNU bash 5.3.20: status 1 in both shapes;
expr.c evalerror -> jump_to_top_level(DISCARD), shell.c:1477 the catch
sets last_command_exit_value). Mirror the plain-command arm's errexit
promotion and consume the command like the Ok(true) arm. Verified
against GNU 5.3.20 script files: group alone on a line, group
mid-line, arithmetic DISCARD in a group, set -e + group, and
'{ z=1; } && echo' all match byte-for-byte including exit status;
tests/issue1318_readonly_assignment_discard back to 5/5.
k6's #1306 emptied BASH_SOURCE under -c by clearing bash_source_stack
at startup. The stored array is what leaked $0 at the -c top level
(declare -p showed [0]="myname"), but the stack seed is load-bearing
elsewhere: the BASH_SOURCE view pops the bottom seed when there is no
main frame, and function entry reads the current source through it —
with the stack cleared, the first function's own frame became the
bottom entry and was popped, so in-function ${BASH_SOURCE[*]} read
empty under -c (GNU 5.3.20: the $0 operand per frame; the repo's
cli_tests function_call_stack_* encode the same shape). Keep the seed
in both seeding orders; only the stored array is emptied. Verified
against GNU 5.3.20: -c top level set-but-empty (declare + ${...-UNSET}),
-c in-function and nested frames, and script-mode frames all match.
… order

k6's #1301 moved ALL name validation ahead of the input read (its
report's model: any invalid name fails before reading, nothing is
assigned, the record stays unread). Measured against GNU bash 5.3.20
that model is wrong in both directions: only the FIRST plain name is
validated before the read (`read 1bad ok <&3` leaves the record
unread, `read ok 1bad later` reads it and keeps ok's value); the -a
argument is validated last, its diagnostic deferred behind the plain
names, and its failure still consumes the record but assigns nothing
(`read -a 1bad x <&3` advances the fd). Restore the measured model:
the early abort now fires only for an invalid first plain name; an
invalid -a argument empties the name lists and lets the scalar read
run for consumption only (fail_after_read); an invalid plain name
anywhere also keeps a valid -a array unassigned; a -a option seen
after the first plain name folds into the plain-name failure (GNU's
option phase has ended there). All nine probed shapes match GNU
5.3.20 byte-for-byte (assignments, diagnostics, fd position);
executor_tests part_048 scalar case passes again — the array case
keeps failing because it encodes pristine's non-GNU fallback
(read -a 1bad ok assigning ok; GNU assigns nothing).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment