Repository navigation
fix(special-paths): fd_alias_target numeric field is canonical decimal (rubash#1973) - #1988
Merged
Merged
Conversation
…l (rubash#1973) The special-path registry accepted leading-zero fd spellings (/dev/fd/00, /dev/fd/03, /dev/fd/007, /proc/self/fd/00) that GNU bash rejects on every face. On Windows, `cat /dev/fd/03 3<<< hi` really read fd 3 (printed "hi", rc 0) where GNU 5.3.20 fails ENOENT even with fd 3 genuinely open; `exec 0</dev/fd/00` silently duplicated fd 0 where GNU prints ENOENT; `echo x | cat /dev/fd/00` read the pipe where GNU fails ENOENT. The wrong registry answer was pinned as "expected" by the special_paths battery, and the R3 convergence pass stopped at three faces that still carried literal fd-0 tables. GNU C source (specification): - redir.c:601 _redir_special_filenames: the /dev/fd/[0-9]* interception exists only #if !defined(HAVE_DEV_FD); on the oracle platform (Linux) HAVE_DEV_FD is set and the literal open decides. procfs serves only canonical names (no leading zeros), so the leading-zero family fails ENOENT everywhere (issue #1973 oracle probes, bash 5.3.20(1)-release: cat ENOENT, redirect ENOENT, test -r false, [[ -e ]] false, source ENOENT). - redir.c:630 redir_special_open RF_DEVFD fallback: all_digits(filename+8) && valid_number && lfd == (int)lfd; all_digits (general.c:233) never admits a sign. Changes: - src/special_paths.rs fd_alias_target: numeric field now parsed by a canonical_decimal helper — ASCII digits only, no sign/whitespace, no leading zero ("0" itself excepted), u32 range. Battery pin (/dev/fd/03 -> FdAlias(3)) replaced with the GNU-correct Filesystem answers for the whole leading-zero family plus sign spellings; legacy mirror updated to the corrected judgment so the drift trip-wire stays live; new per-spelling regression pin issue1973_leading_zero_fd_spellings_are_not_aliases. - Face convergence to fd_alias_target(..) == Some(0) / Some(1)|Some(2), lossless after the registry fix because the accepted spelling sets are unchanged: - src/builtins/test.rs virtual_device_test: fd-0 and fd-1/2 literal tables (was test.rs:619 and :631) now query the registry. - src/builtins/source.rs:178 fd-0 arm now queries the registry. - src/executor/trap_exec.rs:3453 exec-redirect fd-0 arm now queries the registry. - tests/issue1973_leading_zero_fd_aliases_regressions.rs: behavior pins for all three faces (cat operand, pipeline, source, exec redirect, test/[[), expectations from GNU 5.3.20 probes. Verification (WSL GNU bash 5.3.20, script files): - probe scripts + raw outputs under D:/repo/nbbuild/pkg2/ (gnu-probe-results.txt vs before-results.txt vs after-results.txt): after the fix rubash matches GNU on every semantic line; the only diffs are diagnostic path prefixes. - cargo test --release (CARGO_TARGET_DIR=D:/repo/nbbuild/pkg2/target): special_paths lib 3/3, dev_fd_operands lib 2/2, new issue1973 file 5/5, issue1642 13/13, issue700 5/5, issue938 3/3, issue1373 3/3, issue355 10/10, issue429 8/8, regression.rs r3_ 5/6. - Pre-existing on this machine (A/B-verified against pristine 7f51922, not caused by this change): issue1467 (Broken pipe stderr noise), issue396 3/4, regression r3_external_operand_plus_fd_spelling_rejected (external cat not found in the test child's PATH). issue1708 does not compile on Windows (Unix-only imports), excluded. Disclosure: `cargo fmt` fails at master scale with os error 206 (filename too long), so the pre-commit fmt hook cannot run; committed with --no-verify. rustfmt --edition 2021 was run explicitly on the five touched files and `--check` passes clean on them.
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.
Closes #1973.
What was wrong
The special-path registry's
fd_alias_targetaccepted leading-zero fdspellings (
/dev/fd/00,/dev/fd/03,/dev/fd/007,/proc/self/fd/00) that GNU bash rejects on every face, and theregistry battery pinned the wrong answer as expected
(
("/dev/fd/03", FdAlias(3))). On Windows this madecat /dev/fd/03 3<<< hireally read fd 3 (printedhi, rc 0) where GNU fails ENOENT,exec 0</dev/fd/00silently duplicated fd 0, andecho x | cat /dev/fd/00read the pipe. The R3 pass (PR #1971) stopped itsconvergence at three faces precisely because the registry itself was
the divergent side.
GNU C source (specification)
redir.c:601 _redir_special_filenames: the/dev/fd/[0-9]*interception exists only
#if !defined(HAVE_DEV_FD); on the oracleplatform (Linux)
HAVE_DEV_FDis set and the literal opendecides — procfs serves only canonical names, so the leading-zero
family fails ENOENT everywhere.
redir.c:630 redir_special_openRF_DEVFD fallback requiresall_digits(filename+8)(general.c:233) — never a sign.Oracle probes (WSL GNU bash 5.3.20(1)-release, script files):
cat ENOENT, redirect ENOENT,
test -rfalse,[[ -e ]]false,sourceENOENT — including with fd 3 genuinely open.Changes (every face converged, file:line)
src/special_paths.rs:127 fd_alias_target+new
canonical_fd_number(src/special_paths.rs:150): numericfield is canonical decimal — ASCII digits only, no sign, no
whitespace, no leading zero ("0" itself excepted), u32 range.
src/special_paths.rstests: the wrong pinreplaced by the GNU-correct
Filesystemanswers for the wholeleading-zero family (and the sign spellings kept pinned); legacy
mirror updated to the corrected judgment so the drift trip-wire
stays live; new per-spelling pin
issue1973_leading_zero_fd_spellings_are_not_aliases.src/builtins/test.rs:619(virtual_device_testfd-0 table) and
:635(fd-1/2 table): literal tables → registryqueries (
fd_alias_target == Some(0)/Some(1)|Some(2)).src/builtins/source.rs:178fd-0 arm →fd_alias_target(filename) == Some(0).src/executor/trap_exec.rs:3453exec-redirect fd-0arm →
fd_alias_target(&target) == Some(0).tests/issue1973_leading_zero_fd_aliases_regressions.rs(5 tests,one per face + controls).
Convergence is lossless after (1): the registry's accepted spelling
sets for fds 0/1/2 are exactly the literal tables' sets.
Before / after vs GNU 5.3.20 (script-file probes)
cat /dev/fd/03 3<<< hihirc=0 (read fd 3)cat /dev/fd/007 7<<< hihirc=0 (read fd 7)echo body | cat /dev/fd/00bodyrc=0 (read fd 0). /dev/fd/00 <<< textexec 0</dev/fd/00[[ -e /dev/fd/00 ]]/test -r /dev/fd/03echo hi | cat /dev/fd/0,. /dev/fd/0 <<< …,[[ -e /dev/fd/0 ]],. /proc/self/fd/0 <<< …cat /dev/fd/+3 3<<< hiAfter the fix, rubash matches GNU on every semantic line; the only
probe diffs are diagnostic path prefixes.
Tests
cargo test --release,CARGO_TARGET_DIR=D:/repo/nbbuild/pkg2/target,baseline 7f51922:
special_pathslib: 3/3 (battery + new pin)dev_fd_operandslib (R3/D1 pins): 2/2issue1973_leading_zero_fd_aliases_regressions: 5/5issue396 1/4*, issue1373 3/3, issue355 10/10, issue429 8/8,
issue1557 (0 tests, Windows-empty)
regression.rs -- r3_: 5/6** A/B-verified failing identically at pristine 7f51922 on this
machine — environment-bound (pipe-lifetime stderr noise; external
catnot resolvable in the test child's PATH), not caused by thischange.
issue1708does not compile on Windows (Unix-only imports),excluded.
Disclosure
cargo fmtfails at master scale (os error 206), so the pre-commit fmthook cannot run: committed with
--no-verify.rustfmt --edition 2021was run explicitly on the five touched files;
--checkpasses cleanon them.