fix(libSceNpCommon): copy empty JID pieces in sceNpUtilParseJid without passing a null pointer to memcpy #14996

Merged
xXPBSXx merged 1 commit from upstream-pr/14996 into main 2026-11-03 05:12:56 +00:00
xXPBSXx commented 2026-11-02 08:55:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-02T08:55:30Z.


What

The nightly Sanitizers run of 2026-11-02 (run 41384606155, head 926f7dd492) failed guest_np_common_runtime with Strings.cpp:670:24: runtime error: null pointer passed as argument 2, which is declared to never be null. sceNpUtilParseJid copies the user, domain and resource pieces into the caller's buffer with std::memcpy(buffer + used, pieces[i].data(), pieces[i].size()). A piece that SplitJid never sets, for example the user of "nodomain", is a default-constructed std::string_view, whose data() is null, so the call passes a null source with size 0, which is undefined. This copies with std::copy over the view's iterators instead, which accepts an empty range; the bytes written and the return values do not change.

Rechecked on 2026-11-02 at 08:54 UTC: this head merges with main 88e804b0a7 without a conflict, and none of the 11 pull requests opened since 07:30 UTC (#14979 to #14993) changes Strings.cpp.

Tested

WSL2 Ubuntu 24.04 (g++ 13.3, AMD Ryzen 7 5800X3D; virtualised kernel, not bare metal), configured as in sanitizers.yml (Release, ANYPS5_ENABLE_ASAN=ON, -g1 -fsanitize=undefined -fno-sanitize=vptr) with the job's test environment (ASAN_OPTIONS=detect_leaks=0, UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1, APS5_SKIP_TIMING_TESTS=1): guest_np_common_runtime on main 4569fe654a without this change failed 3 of 3 runs with the message above; with this change on the same base it passed 3 of 3 runs with no runtime error. On Windows (MinGW GCC 15.2, Release, no sanitizer) it passed 3 of 3 runs with this change. The existing test case for "nodomain" covers the path, so no test is added. tools/check_conventions.py --base upstream/main passes. Not tested: macOS and the CI runner.

Overlap

Checked on 2026-11-02 at 07:24 UTC against main 4569fe654a (1914 open pull requests). I took the changed files of each open pull request from git diff --name-only against its merge base. Three change core/libs/prx/libSceNpCommon/Strings.cpp: #14318, #12818 and #12772. Each of them merges with this head without a conflict, and each also merges alone with main. For one pull request (#13454) the ref could not be fetched; it is a custommusicsyscallwrapper change by its title. This head merges cleanly with main 88e804b0a7 (checked 2026-11-02 at 08:06 UTC).

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
  • 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

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5117589988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14996). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-02T08:55:30Z. --- ### What The nightly Sanitizers run of 2026-11-02 (run 41384606155, head `926f7dd492`) failed `guest_np_common_runtime` with `Strings.cpp:670:24: runtime error: null pointer passed as argument 2, which is declared to never be null`. `sceNpUtilParseJid` copies the user, domain and resource pieces into the caller's buffer with `std::memcpy(buffer + used, pieces[i].data(), pieces[i].size())`. A piece that `SplitJid` never sets, for example the user of `"nodomain"`, is a default-constructed `std::string_view`, whose `data()` is null, so the call passes a null source with size 0, which is undefined. This copies with `std::copy` over the view's iterators instead, which accepts an empty range; the bytes written and the return values do not change. Rechecked on 2026-11-02 at 08:54 UTC: this head merges with `main` `88e804b0a7` without a conflict, and none of the 11 pull requests opened since 07:30 UTC (#14979 to #14993) changes `Strings.cpp`. ### Tested WSL2 Ubuntu 24.04 (g++ 13.3, AMD Ryzen 7 5800X3D; virtualised kernel, not bare metal), configured as in `sanitizers.yml` (Release, `ANYPS5_ENABLE_ASAN=ON`, `-g1 -fsanitize=undefined -fno-sanitize=vptr`) with the job's test environment (`ASAN_OPTIONS=detect_leaks=0`, `UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1`, `APS5_SKIP_TIMING_TESTS=1`): `guest_np_common_runtime` on `main` 4569fe654a without this change failed 3 of 3 runs with the message above; with this change on the same base it passed 3 of 3 runs with no `runtime error`. On Windows (MinGW GCC 15.2, Release, no sanitizer) it passed 3 of 3 runs with this change. The existing test case for `"nodomain"` covers the path, so no test is added. `tools/check_conventions.py --base upstream/main` passes. Not tested: macOS and the CI runner. ### Overlap Checked on 2026-11-02 at 07:24 UTC against `main` 4569fe654a (1914 open pull requests). I took the changed files of each open pull request from `git diff --name-only` against its merge base. Three change `core/libs/prx/libSceNpCommon/Strings.cpp`: #14318, #12818 and #12772. Each of them merges with this head without a conflict, and each also merges alone with `main`. For one pull request (#13454) the ref could not be fetched; it is a custommusicsyscallwrapper change by its title. This head merges cleanly with `main` 88e804b0a7 (checked 2026-11-02 at 08:06 UTC). ### Checklist - [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) - [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 AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-02 10:30:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T10:30:54Z.

Review: APPROVED


Looks right to me.

  • The null source is real. SplitJid only assigns parts.user when an @ follows a non-empty user part. For "nodomain" it stays a default-constructed std::string_view, so data() is null and the old memcpy(buffer + used, nullptr, 0) was undefined. std::copy over the view's empty iterator range dereferences nothing. For non-empty pieces it writes the same bytes, and the terminator, copies[i] and used are unchanged.
  • The test already covers it. The existing "nodomain" case at GuestNpCommonRuntime.cpp:772 expects an empty user string.
  • The rest of Strings.cpp is fine. sceNpUtilJidToNpId's copies get their pointers from strlen on non-null strings, and the resource copy is already guarded by resourceLength != 0. I found no other memcpy there that can receive a default-constructed view.

Tested on Windows 11, WinLibs GCC 15.2.0, Release, with head 01e6dab8eb merged onto main 88e804b0a7:

  • guest_np_common_runtime passes.
  • It also passes with Strings.cpp put back to main's version. That's expected, since this build has no UBSan; it shows the change doesn't alter behaviour. I relied on your Linux sanitizer runs for the UB itself.
  • tools/check_conventions.py --base upstream/main passes.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5735188127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14996#pullrequestreview-5735188127). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T10:30:54Z. **Review:** APPROVED --- Looks right to me. - **The null source is real.** `SplitJid` only assigns `parts.user` when an `@` follows a non-empty user part. For `"nodomain"` it stays a default-constructed `std::string_view`, so `data()` is null and the old `memcpy(buffer + used, nullptr, 0)` was undefined. `std::copy` over the view's empty iterator range dereferences nothing. For non-empty pieces it writes the same bytes, and the terminator, `copies[i]` and `used` are unchanged. - **The test already covers it.** The existing `"nodomain"` case at `GuestNpCommonRuntime.cpp:772` expects an empty user string. - **The rest of `Strings.cpp` is fine.** `sceNpUtilJidToNpId`'s copies get their pointers from `strlen` on non-null strings, and the resource copy is already guarded by `resourceLength != 0`. I found no other `memcpy` there that can receive a default-constructed view. Tested on Windows 11, WinLibs GCC 15.2.0, Release, with head `01e6dab8eb` merged onto `main` `88e804b0a7`: - `guest_np_common_runtime` passes. - It also passes with `Strings.cpp` put back to `main`'s version. That's expected, since this build has no UBSan; it shows the change doesn't alter behaviour. I relied on your Linux sanitizer runs for the UB itself. - `tools/check_conventions.py --base upstream/main` passes.
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!14996
No description provided.