Skip to content

Refs #3105 - #3127

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3105-argv-positional-encoding
Nov 9, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3105-argv-positional-encoding

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #3105

问题

OS-argv 位置参数未按存储域契约编码入存储:用户载体字节以裸字符进入 positional params,单词定型时裸 \x1c 被当作 IFS_GLUE 协议标记剥除——值在存储内「看得见」(case 匹配、子串提取都命中),展开成词却丢字节,导出给真子进程也丢。环境变量入口已由 #2884 在导入处编码,argv 入口没走。

GNU 锚点:shell.c:1505-1515(-c 形 dollar_vars 逐字绑定 + remember_args)、shell.c:1613-1614(脚本名)、variables.c:368 initialize_shell_variables(environ 逐字存)——GNU 无传输域故逐字即正确;rubash 有存储域契约,原始数据入口必须以数据编码(entry_encode_value_text,与 env 导入同一编码器)入存储。

修法(队长已裁契约面)

编码落在原始数据入口,不动共用 setter set_positional_params 本体(set 内建/函数调用给它的是熟词,落在 setter 必双重编码):

  • 二进制:main.rs 三处 OS argv 直设(-c 形、脚本文件形、-s 形)。
  • 宿主 API:StateViews::set_positional(api/views.rs)、Session::set_positional(api/session.rs)——宿主传原始数据、引擎在入口编码,签名不变。
  • 宿主 invocation:ShellInvocation::apply_to_executor_before_startup 落存储前编码(invocation.rs)。
  • 同族普查同病同修:BASH_ARGV0 的原始数据种子(env 导入的原样复播种、argv[0] 显示形种子、-c 名操作数、脚本名种子、invocation command_name 种子)——它是 shell 可见变量,按变量存储契约编码;__RUBASH_* 内部传输身份名保持原样不动。
  • 编码器不新增公开面:仓内落点直接用 substitution_metadata::entry_encode_value_text;二进制面复用既有公开 bytes_to_shell_text(其 valid-text 臂与 entry_encode_value_text 的 escape 按模块文档恒等)。api-ledger 不动。

本 PR 删除了什么

无删除。本 PR 为纯新增:各原始入口在落存储前逐值编码,回归钉一个文件。净行数以最终 diff 为准。

验证

UNVERIFIED-BY-CAPTAIN(车道自报,队长复核为准):钉 fail-first 与全腿数字见车道 REPORT。

OS-argv positional parameters enter storage unencoded: a bare
carrier byte in $1 is stripped as IFS_GLUE protocol when the
value is finalized into a word, while storage-domain consumers
(case, substring) still see it. GNU binds argv verbatim
(shell.c:1505-1515 remember_args; variables.c:368 environ
verbatim) — rubash's storage contract therefore requires every
raw-data entry to encode at its boundary, the way environment
import already does (rubash#2884).

Cells: -c / script-file / -s argv faces, export to a real child,
Session + StateViews set_positional, ShellInvocation apply, the
$0/BASH_ARGV0 survey faces, plus controls (case, substring, env
entry, marker-zone verbatim) and the set-builtin double-encode
guard.
OS argv entered storage unencoded: a bare carrier byte (e.g. \x1c)
in $1 stayed visible to storage-domain consumers (case, substring)
but was stripped as IFS_GLUE protocol at word finalization, and was
lost again on export to real children. GNU binds argv verbatim
(shell.c:1505-1515 the -c face, shell.c:1613-1614 the script-name
$0, variables.c:368 environ) because it has no transport domain;
this engine's storage contract entry-encodes raw data, as the
environment import already does, so the argv entries encode here.

Landing points (raw data only): the -c / -s / script-file faces in
main.rs, StateViews::set_positional, Session::set_positional, and
ShellInvocation::apply_to_executor_before_startup, plus the
BASH_ARGV0 raw-data seed family found by census (the env re-seed,
the argv[0] display seed, the -c name operand, the script name, the
invocation command_name). The shared set_positional_params setter
is untouched: the set builtin, function calls and source args hand
it cooked shell words, and encoding there would double-encode them.
__RUBASH_* internal transport identity carriers keep raw spelling.

Refs #3105
@caomengxuan666
caomengxuan666 merged commit 5fad754 into master Nov 9, 2026
11 checks passed
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