Repository navigation
fix(api): OptionsView recognizes flag-only shell options (restricted) — #2040 - #2148
Merged
Merged
Conversation
#2040 Root cause: OptionsView::set (src/api/views.rs:378) dispatches on is_shell_option — membership in the `set -o` table (SHELL_OPTIONS, src/builtins/set/options.rs:12) — and falls through to the shopt table otherwise. GNU `restricted` lives in neither: it is a flag-only option, owned by the single-letter shell_flags[] table (flags.c:182 { 'r', &restricted }), absent from the `set -o` enumeration (set.def:194-237 o_options[]) and from SHELLOPTS. The set builtin arms it directly (`set -r` -> set_shell_option(env_vars, "restricted", ...), src/builtins/set.rs:327, no family gate), so the set machine was wider than the view's dispatch predicate: a legal flag-only name returned false with no state change (rubash#2040, found by the #668 watch face; niu worked around it by bypassing the view — PR #668 310d5e2). Fix (the issue's disposition 1: let the view recognize flag options): - src/builtins/set/options.rs: new is_flag_only_shell_option() whitelist beside is_shell_option, naming the GNU class (shell_flags[] vs o_options[]); sole instance `restricted`. - src/api/views.rs OptionsView::set: flag-only names route through the same set_shell_option machinery the `set -r` builtin branch uses, with GNU's one-way gate intact (change_flag refuses FLAG_OFF while the option is on, flags.c:231-233): armed && !enabled returns false, no state change. No second write path. - src/executor/state_views.rs view_option_enabled: flag-only names read through the same key the executor's restricted-shell consumers consult (shell_option_enabled), keeping get/set symmetric. - src/api/session.rs: Session::options doc mentions the flag surface. Invariants pinned by tests/issue2040_optionsview_flagonly_regressions.rs (external-consumer style, rubash::api only; 7/7 green): - set("restricted", true) arms and returns true; get reads Some(true) (pre-fix: false/None — A/B on pristine d5c172a fails 6/7). - Arming is the live persona: `cd` refused ("cd: restricted") and PATH read-only ("PATH: readonly variable") immediately after arming (maybe_make_restricted, shell.c:1278-1299, via the shared machinery). - set("restricted", false) while armed: refused, false, state intact (flags.c:231-233); while unarmed: successful no-op. - `restricted` stays out of list() and SHELLOPTS (that is what flag-only means); both known families dispatch unchanged; unknown names still refuse. Verification: CARGO_TARGET_DIR build, cargo test --release --lib 1063 passed; adjacent integration targets green (shopt/set/restricted/ session_threading/interrupt/posix-roundtrip etc.). Full `cargo test --release` is blocked at pristine master by tests/typed_cell_coherence_fuzz.rs calling the #[cfg(debug_assertions)] Executor::verify_typed_cells_forced (variable_state.rs:962, fecc9f9) — pre-existing, unrelated. Remaining failures A/B-identical on pristine: issue1306 (BASH_SOURCE in -c), session_api::build_run_and_state_views_ round_trip (temp-cwd canonicalize), multi_session_isolation matrix, issue0171 family (std::os::unix, non-Windows compile). Fmt disclosure: `cargo fmt` aborts with os error 206 (command line too long) in this environment (known hook precedent); the six touched files were formatted with direct rustfmt (rc 0), so --no-verify is used for this commit. Fixes: #2040
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.
Fixes #2040 (found by the #668 watch face; niu's interim bypass was executor-direct writes, PR #668 310d5e2 — this restores the view as the sanctioned path).
Root cause
OptionsView::set(src/api/views.rs:378 @ d5c172a) dispatches onis_shell_option— membership in theset -otable (SHELL_OPTIONS, src/builtins/set/options.rs:12) — and falls through to the shopt table otherwise. GNUrestrictedlives in neither:flags.c:182 { 'r', &restricted }inshell_flags[];set -oenumeration:set.def:194-237 o_options[](vendored tree @9c465866);set -olistings orSHELLOPTS.The set builtin arms it directly through the letter branch (
set -r→set_shell_option(env_vars, "restricted", ...), src/builtins/set.rs:327, no family gate), so the set machine was wider than the view's dispatch predicate: a legal flag-only name fell through both families, returnedfalse, and changed nothing — silently.Fix (issue disposition 1: let the view recognize flag options)
src/builtins/set/options.rs: newis_flag_only_shell_option()whitelist besideis_shell_option, naming the GNU class (shell_flags[] vs o_options[]); sole instancerestricted.src/api/views.rsOptionsView::set: flag-only names route through the sameset_shell_optionmachinery theset -rbuiltin branch uses — no second write path — with GNU's one-way gate intact:change_flagrefuses FLAG_OFF while the option is on (flags.c:231-233), soset("restricted", false)on a live restriction returnsfalsewith no state change; while unarmed it is a successful no-op (set +rwrites 0 over 0).src/executor/state_views.rsview_option_enabled: flag-only names read through the same key the executor's restricted-shell consumers consult, keepingget/setsymmetric over the flag surface.src/api/session.rs:Session::optionsdoc mentions the flag surface.Regression test —
tests/issue2040_optionsview_flagonly_regressions.rs(7/7)External-consumer style (
rubash::apionly):set("restricted", true)arms, returnstrue;get→Some(true)false/None)cdrefused (cd: restricted),PATHread-only (PATH: readonly variable) —maybe_make_restricted, shell.c:1278-1299, via the shared machineryset("restricted", false)while armed → refused,false, state intact (flags.c:231-233)restrictedstays out oflist()andSHELLOPTS(that is what flag-only means)A/B vs pristine (origin/master d5c172a)
CARGO_TARGET_DIR=D:/repo/nbbuild/pkg11/H3/target cargo test --release:--lib: 1063 passed, 0 failed.issue1487,issue346_348,issue705,issue1941_1948), restricted (issue527,issue626,issue804), session threading/interrupt, posix roundtrip.cargo test --releaseis blocked at pristine master bytests/typed_cell_coherence_fuzz.rscalling the#[cfg(debug_assertions)]Executor::verify_typed_cells_forced(variable_state.rs:962, fecc9f9) — pre-existing, unrelated to this branch.issue1306(BASH_SOURCE in-c),session_api::build_run_and_state_views_round_trip(temp-cwd canonicalize),multi_session_isolationmatrix,issue0171family (std::os::unix — non-Windows compile).Fmt disclosure
cargo fmtaborts with os error 206 (command line too long) in this environment (known hook precedent); the six touched files were formatted with directrustfmt(rc 0), so--no-verifyis used for the commit.禁区 check: src/lexer/continuation.rs untouched; no carrier-byte changes; LF throughout; no elevation.