fix(libkernel): skip the sysctl copy-out when no bytes are copied #10921

Merged
MarcZX10 merged 1 commit from upstream-pr/10921 into main 2026-10-26 09:05:31 +00:00
MarcZX10 commented 2026-10-25 10:17:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T10:17:27Z.


What

CopyOut in libkernel/System/src/SystemConfiguration.cpp called std::memcpy(oldValue, value, copied) with a null value for the kern.proc.env query ({1, 14, 35, pid}), which reports no data. copied is 0 there, but a null source pointer is undefined behavior for memcpy whatever the length, and UBSan reports it (null pointer passed as argument 2, which is declared to never be null). The copy now happens only when copied is not 0. Results, lengths and errno are unchanged. One commit: fix; no new test is needed because the existing CheckEnvSysctl case already makes this exact call (output buffer non-null, length 16, no new value).

Tested

Linux x86-64 (Debian 12, GCC 12), Release with ASan+UBSan. On current main, guest_system_configuration aborts on the UBSan report above; with this change it passes (ctest -R '^guest_system_configuration$'). python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check upstream/main pass. Windows, macOS and hardware were not run.

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 (not applicable; no third-party code added)
  • 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:5003838157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10921). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T10:17:27Z. --- ### What `CopyOut` in `libkernel/System/src/SystemConfiguration.cpp` called `std::memcpy(oldValue, value, copied)` with a null `value` for the `kern.proc.env` query (`{1, 14, 35, pid}`), which reports no data. `copied` is 0 there, but a null source pointer is undefined behavior for `memcpy` whatever the length, and UBSan reports it (`null pointer passed as argument 2, which is declared to never be null`). The copy now happens only when `copied` is not 0. Results, lengths and errno are unchanged. One commit: fix; no new test is needed because the existing `CheckEnvSysctl` case already makes this exact call (output buffer non-null, length 16, no new value). ### Tested Linux x86-64 (Debian 12, GCC 12), Release with ASan+UBSan. On current `main`, `guest_system_configuration` aborts on the UBSan report above; with this change it passes (`ctest -R '^guest_system_configuration$'`). `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check upstream/main` pass. Windows, macOS and hardware were not run. ### 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) - [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 (not applicable; no third-party code added) - [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
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!10921
No description provided.