Skip to content

modernish 套件启动期死于真实 use 加载上下文(harden.mm 级联误报,生态审计 DIV-F2) #2033

Closed

Description

@caomengxuan666

生态全链审计(~/workspace/audit2-eco/REPORT.md §DIV-F2)。DIV-F 原形态(入口解析失败)已消失,bin/modernish -n rc=0;但套件跑不起来:--test 与点链 rc=128 零产出,第一错误 lib/modernish/mdl/sys/cmd/harden.mm: line 163: syntax error near unexpected token 'fi'(case 模式表内续行)。

隔离边界:该文件整体 -n 双边 rc=0、函数体抽出 -n rc=0、直接 source 双边一致、模式表四变体(裸保留字/转义/续行/全形)全过——触发需要 modernish 真实 use 加载上下文(初始化序列),未隔离到单一构造。更小复现框:vendor 树内 printf 'use sys/cmd/harden\ntype -t harden\n' | <shell> bin/modernish——GNU 干净输出 function;rubash 初始化期即 readonly function 级联报错 + 其生成的 POSIX-trap -c 串 syntax error(该 -c 串双边未必同串,只作复现框不作单构造归因)。证据:audit2-eco 工区 files/modernish/、files/divf2/。

归宿:清零后第一批(parser/生态归因批),先隔离单一构造再谈修。

Activity

  1. added
    bug
    on Oct 29, 2026
  2. added
    gnu-baseline
    P2-medium
    area:parser
    on Oct 29, 2026
  3. added this to the 1.5.0 milestone on Oct 29, 2026
  4. caomengxuan666 commented on Oct 29, 2026

    @caomengxuan666
    MemberAuthor

    Root cause (isolated + fixed)

    The alias-live gather's streaming alias expander pre-pass — ComsubAliasScanner::drive in src/lexer/alias_stream.rs — had no # comment arm (and neither did its batch twin expand_comsub_alias_bodies). An apostrophe inside a comment (# sys/cmd/harden: modernish's replacement for 'set -e' ..., harden.mm line 4) opened a phantom single-quote string:

    • batch pre-pass: the quote skip swallowed the rest of the input, hiding real $(…) units from alias expansion (a latent second bug: aliases inside a comsub that follows an apostrophe-comment never expanded);
    • streaming pre-pass: the unterminated quote parked the phase across whole input spans (rescan_park + retry_deadline span throttle), so the gather's feeder/battery completeness machines were fed in bursts instead of per line. Their state diverged from the non-alias arm and the verdict wrongly blessed a mid-function group cut — harden.mm lines 4..276 of 404, cutting harden() mid-body. The cut chunk fails to parse standalone, surfacing at the \esac mode table (line 163; the non-monotone error lines across content cuts are just wherever the wrong cut lands).

    This is why the trigger is exactly expand_aliases + ≥1 alias defined: without a live alias table the gather takes the raw arm, which gathers the same file correctly. It also explains why eval "$(cat t3.mm)" (whole-string batch parse) was clean while . t3.mm failed.

    GNU anchor: parse.y:3631-3645 shell_getc — # at a shell_getc position ALWAYS comments ("Discard until EOL or EOF"); a mid-word # (echo a#b) never reaches shell_getc because read_token_word consumes word characters without returning to the character feeder. Probed on WSL GNU Bash 5.3: echo a#b → a#b; echo >#f → syntax error (# after > IS a comment); $( # hi ' there <NL> echo IN ) → IN.

    Fix (branch fix/2033-modernish-use-2, commit 4e3d4d3)

    Both pre-pass walkers get an at_word_start token-boundary state (true after input start / blank / newline / ; & | ( ) < >); # at a token start is skipped to EOL inert (no quote tracking). The streaming form parks only when the comment's newline is not yet fed, mirroring MainAliasScanner's own # arm. stream==batch preserved by construction.

    Verification

    • tests/issue2033_alias_comsub_comment_park_regressions.rs (3 tests): the sourced-hardem-module frame and the comsub-after-comment pin both fail on the pre-fix binary, pass on the fixed build; mid-word a#b stays literal.
    • End-to-end: use sys/cmd/harden + type -t harden → function, rc=0 (full LF modernish clone @1d838eb); multi-module use + repeat-use smoke green.
    • alias_stream streaming-contract unit tests 7/7.
    • Comment-class GNU matrix (10 rows): byte-identical to GNU except two rows pre-existing identically on pristine (alias-value-with-comment, heredoc delimiter edge — separate gaps, unchanged by this fix).
    • true-baseline A/B, 19 suites (alias case casemod comsub comsub2 comsub-eof comsub-posix heredoc iquote nquote nquote1-5 quote quotearray redir vredir): fixed ledger == pristine ledger per suite — no regression.

    Note: var/num/random still fails on both binaries (syntax error in the bin/modernish -c die-trap path) — pre-existing, separate from this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2-mediumarea:parserbuggnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions