fix(libc): count a backslash as a name character for NAME_MAX, as FreeBSD 11.4 does #22042

Open
brajankw wants to merge 1 commit from upstream-pr/22042 into main
brajankw commented 2026-11-17 03:06:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T03:06:05Z.


What

The guest path resolver reset the component length at a backslash, as at a slash, so a 301-byte name containing one passed the NAME_MAX check. FreeBSD 11.4's namei treats a backslash as an ordinary name character (the Guest path names entry in docs/dev/debt/libc.md, which GuestPathNameLength.cpp pinned with "FreeBSD would refuse the 301-byte name").

  • Only a slash ends a component for the length check in Resolve (General.cpp); such a name now fails with ENAMETOOLONG. The resolver still turns a backslash into a slash before the host call, which the debt entry keeps as the remaining gap.
  • GuestPathNameLength.cpp: 200 + \ + 100 bytes fails with ENAMETOOLONG; 127 + \ + 127 (255 bytes) does not.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main ec7369ecb8.

  • ctest -R '^guest_path_name_length$': passed.
  • Negative control: with main's General.cpp and this branch's test, guest_path_name_length fails at the 301-byte check (ENOENT instead of ENAMETOOLONG).
  • Full ctest (5896 tests, -j 12) with this branch and my other twelve branches of this round merged onto main 521fb7fec4: 5880 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, network or a passwd entry for the user.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch: failed closed on #20315, which conflicts with main; its diff does not touch the name-length loop.
  • Not tested on Windows or macOS. No title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5349749304 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22042). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T03:06:05Z. --- ### What The guest path resolver reset the component length at a backslash, as at a slash, so a 301-byte name containing one passed the `NAME_MAX` check. FreeBSD 11.4's `namei` treats a backslash as an ordinary name character (the `Guest path names` entry in `docs/dev/debt/libc.md`, which `GuestPathNameLength.cpp` pinned with "FreeBSD would refuse the 301-byte name"). - Only a slash ends a component for the length check in `Resolve` (`General.cpp`); such a name now fails with `ENAMETOOLONG`. The resolver still turns a backslash into a slash before the host call, which the debt entry keeps as the remaining gap. - `GuestPathNameLength.cpp`: 200 + `\` + 100 bytes fails with `ENAMETOOLONG`; 127 + `\` + 127 (255 bytes) does not. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `ec7369ecb8`. - `ctest -R '^guest_path_name_length$'`: passed. - Negative control: with `main`'s `General.cpp` and this branch's test, `guest_path_name_length` fails at the 301-byte check (`ENOENT` instead of `ENAMETOOLONG`). - Full `ctest` (5896 tests, `-j 12`) with this branch and my other twelve branches of this round merged onto `main` `521fb7fec4`: 5880 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, network or a passwd entry for the user. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch`: failed closed on #20315, which conflicts with `main`; its diff does not touch the name-length loop. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 03:09:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T03:09:23Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c6be8027de:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_path_name_length_tests built cleanly.
  • CTest (guest_path_name_length):
    1/1 Test #5443: guest_path_name_length ...........   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/General.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5443: guest_path_name_length ...........Subprocess aborted***Exception:   0.39 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libc/src/General.cpp:401 component length loop correctly counts backslash ('\') as a regular filename character rather than resetting component length, adhering to FreeBSD 11.4 namei NAME_MAX semantics.
    • Verified error throwing behavior when component length exceeds MaxName (255 bytes) produces std::filesystem::filesystem_error with std::errc::filename_too_long (ENAMETOOLONG / 63).
    • Verified docs/dev/debt/changes/fix-libc-path-backslash-name-length.md accurately records the updated behavior and remaining gap without AGENTS.md rule violations.
    • Verified core/libs/tests/GuestPathNameLength.cpp adequately tests positive and negative bounds (255 bytes with backslash passes, 301 bytes with backslash fails with ENAMETOOLONG).

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5932126789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22042#pullrequestreview-5932126789). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T03:09:23Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c6be8027de`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_path_name_length_tests` built cleanly. - **CTest** (`guest_path_name_length`): ``` 1/1 Test #5443: guest_path_name_length ........... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/src/General.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5443: guest_path_name_length ...........Subprocess aborted***Exception: 0.39 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified core/libs/prx/libc/src/General.cpp:401 component length loop correctly counts backslash ('\\') as a regular filename character rather than resetting component length, adhering to FreeBSD 11.4 namei NAME_MAX semantics. - Verified error throwing behavior when component length exceeds MaxName (255 bytes) produces std::filesystem::filesystem_error with std::errc::filename_too_long (ENAMETOOLONG / 63). - Verified docs/dev/debt/changes/fix-libc-path-backslash-name-length.md accurately records the updated behavior and remaining gap without AGENTS.md rule violations. - Verified core/libs/tests/GuestPathNameLength.cpp adequately tests positive and negative bounds (255 bytes with backslash passes, 301 bytes with backslash fails with ENAMETOOLONG). Looks Good To Me
MarcZX10 commented 2026-11-21 12:50:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:50:28Z.

Review: COMMENTED


Reviewed — comments

The code change matches the stated length-check behavior; the new debt note describes a backslash inconsistently, and I could not run the reported checks.

What I ran

Reviewed head c6be8027decc238433c9e30fca8dad4ce345cbff using the supplied reader. No shell or test execution was available.

Results

Check Result Note
Changed source and test review passed All three changed files read
Automated checks not run Test results are author-reported
Negative control not run Author reports it failed as expected

Findings

Blocking

None.

Non-blocking

  • docs/dev/debt/changes/fix-libc-path-backslash-name-length.md:3 says a backslash counts as a path separator, while its following paragraph and the code change say it counts as a name character. Please correct the heading to describe the intended behavior.

Sources

Not verified

I read all files listed as reviewed: core/libs/prx/libc/src/General.cpp, core/libs/tests/GuestPathNameLength.cpp, and docs/dev/debt/changes/fix-libc-path-backslash-name-length.md. No files were excluded by the manifest. I did not run the test, convention, or overlap checks, and did not verify behavior on Windows, macOS, or a console. The description's reported Linux tests and negative control were not independently verified.

To get this to a good state

Nothing is required. The optional documentation wording correction is noted above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005290551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22042#pullrequestreview-6005290551). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T12:50:28Z. **Review:** COMMENTED --- # Reviewed — comments The code change matches the stated length-check behavior; the new debt note describes a backslash inconsistently, and I could not run the reported checks. ## What I ran Reviewed head `c6be8027decc238433c9e30fca8dad4ce345cbff` using the supplied reader. No shell or test execution was available. ## Results | Check | Result | Note | |---|---|---| | Changed source and test review | passed | All three changed files read | | Automated checks | not run | Test results are author-reported | | Negative control | not run | Author reports it failed as expected | ## Findings ### Blocking None. ### Non-blocking - `docs/dev/debt/changes/fix-libc-path-backslash-name-length.md:3` says a backslash counts as a path separator, while its following paragraph and the code change say it counts as a name character. Please correct the heading to describe the intended behavior. ## Sources - [`General.cpp` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c6be8027decc238433c9e30fca8dad4ce345cbff/core/libs/prx/libc/src/General.cpp) - [`GuestPathNameLength.cpp` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c6be8027decc238433c9e30fca8dad4ce345cbff/core/libs/tests/GuestPathNameLength.cpp) - [`fix-libc-path-backslash-name-length.md` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c6be8027decc238433c9e30fca8dad4ce345cbff/docs/dev/debt/changes/fix-libc-path-backslash-name-length.md) ## Not verified I read all files listed as reviewed: `core/libs/prx/libc/src/General.cpp`, `core/libs/tests/GuestPathNameLength.cpp`, and `docs/dev/debt/changes/fix-libc-path-backslash-name-length.md`. No files were excluded by the manifest. I did not run the test, convention, or overlap checks, and did not verify behavior on Windows, macOS, or a console. The description's reported Linux tests and negative control were not independently verified. ## To get this to a good state Nothing is required. The optional documentation wording correction is noted above.
ligmaSec commented 2026-12-03 11:23:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:23:50Z.

Review: COMMENTED


Built the submitted path checking code and ran the exact GuestPathNameLength fixture on Linux. It passed the new backslash cases, including the accepted 255-byte name and an overlong name containing the same character.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168777632 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22042#pullrequestreview-6168777632). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T11:23:50Z. **Review:** COMMENTED --- Built the submitted path checking code and ran the exact `GuestPathNameLength` fixture on Linux. It passed the new backslash cases, including the accepted 255-byte name and an overlong name containing the same character. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/22042:upstream-pr/22042'
git switch 'upstream-pr/22042'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/22042'
git switch 'upstream-pr/22042'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/22042'
git switch 'upstream-pr/22042'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/22042'
git switch 'main'
git merge --squash 'upstream-pr/22042'
git switch 'main'
git merge --ff-only 'upstream-pr/22042'
git switch 'main'
git merge 'upstream-pr/22042'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!22042
No description provided.