fix(libSceNpCommon): copy empty JID pieces in sceNpUtilParseJid without passing a null pointer to memcpy #14996
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14996"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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) failedguest_np_common_runtimewithStrings.cpp:670:24: runtime error: null pointer passed as argument 2, which is declared to never be null.sceNpUtilParseJidcopies the user, domain and resource pieces into the caller's buffer withstd::memcpy(buffer + used, pieces[i].data(), pieces[i].size()). A piece thatSplitJidnever sets, for example the user of"nodomain", is a default-constructedstd::string_view, whosedata()is null, so the call passes a null source with size 0, which is undefined. This copies withstd::copyover 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
main88e804b0a7without a conflict, and none of the 11 pull requests opened since 07:30 UTC (#14979 to #14993) changesStrings.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_runtimeonmain4569fe654awithout 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 noruntime 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/mainpasses. Not tested: macOS and the CI runner.Overlap
Checked on 2026-11-02 at 07:24 UTC against
main4569fe654a(1914 open pull requests). I took the changed files of each open pull request fromgit diff --name-onlyagainst its merge base. Three changecore/libs/prx/libSceNpCommon/Strings.cpp: #14318, #12818 and #12772. Each of them merges with this head without a conflict, and each also merges alone withmain. For one pull request (#13454) the ref could not be fetched; it is a custommusicsyscallwrapper change by its title. This head merges cleanly withmain88e804b0a7(checked 2026-11-02 at 08:06 UTC).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T10:30:54Z.
Review: APPROVED
Looks right to me.
SplitJidonly assignsparts.userwhen an@follows a non-empty user part. For"nodomain"it stays a default-constructedstd::string_view, sodata()is null and the oldmemcpy(buffer + used, nullptr, 0)was undefined.std::copyover the view's empty iterator range dereferences nothing. For non-empty pieces it writes the same bytes, and the terminator,copies[i]andusedare unchanged."nodomain"case atGuestNpCommonRuntime.cpp:772expects an empty user string.Strings.cppis fine.sceNpUtilJidToNpId's copies get their pointers fromstrlenon non-null strings, and the resource copy is already guarded byresourceLength != 0. I found no othermemcpythere that can receive a default-constructed view.Tested on Windows 11, WinLibs GCC 15.2.0, Release, with head
01e6dab8ebmerged ontomain88e804b0a7:guest_np_common_runtimepasses.Strings.cppput back tomain'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/mainpasses.