feat(libSceLibreSsl): implement X509_VERIFY_PARAM_set1_host #11189

Merged
JaceTheBlu merged 23 commits from upstream-pr/11189 into main 2026-10-29 05:49:45 +00:00
JaceTheBlu commented 2026-10-25 21:10:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JaceTheBlu on 2026-10-25T21:10:06Z.


What

Implements X509_VERIFY_PARAM_set1_host in libSceLibreSsl, which threw and was declared without parameters. It stacks on #11105, which carries #11100 and #11089; the commits before this PR's own are theirs.

int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM*, const char* name, size_t namelen) follows int_x509_param_set_hosts with SET_HOST from LibreSSL 2.7 (OPENBSD_6_3), the first release with this export; 2.5.4, the version the debt file names, lacks it, and its layouts are the same as 2.7's:

  • a non-null name with namelen 0 is measured with strlen;
  • a name with a NUL among its namelen bytes returns 0 and leaves the host list alone;
  • otherwise the list is freed (each name, then the stack), and a null or empty name returns 1 with no list;
  • a non-empty name is copied with the guest strndup, as the module would through libc, and pushed on a new plain stack (4 slots, no comparator); a failed copy or stack allocation frees what it allocated and returns 0 with no list.

LibreSSL 2.8 also sets a poisoned field when the call fails; that field is not in the 2.5.4 to 2.7 parameter identity used here, so a failed call leaves no mark. The debt entry records this. Null verify parameters or identity throw where LibreSSL faults. The pending-export count in docs/dev/debt/libSceLibreSsl.md drops by one.

This branch stacks on #11105, which carries #11100 and #11089 (#11089, #11100, #11105, then this one). Each branch merges the previous one, so the files they share are resolved once along the chain.

Tested

Debian trixie container, GCC 14.2, full Release build of this branch. ctest -R 'libressl|crypto_memcmp': all pass (18 of 18 on the stacked head). guest_libressl_x509_store now also covers this export: terminated and counted names, a counted name without a terminator, an embedded NUL refused with the list kept, null and empty names clearing the list, a name the store frees, and the throwing cases; guest_libressl_x509_store_allocator counts the copy, stack and array allocations, the frees when a name replaces another, and a failed copy and a failed stack allocation. python3 tools/check_conventions.py --base upstream/main passes. Not tested on Windows, on a title or on a console.

tools/pr_overlap.py was not run (no authenticated gh).

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: #11105
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008746807 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11189). Originally posted by [JaceTheBlu](https://github.com/JaceTheBlu) on 2026-10-25T21:10:06Z. --- ### What Implements `X509_VERIFY_PARAM_set1_host` in libSceLibreSsl, which threw and was declared without parameters. It stacks on #11105, which carries #11100 and #11089; the commits before this PR's own are theirs. `int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM*, const char* name, size_t namelen)` follows `int_x509_param_set_hosts` with `SET_HOST` from [LibreSSL 2.7](https://github.com/libressl/openbsd/blob/OPENBSD_6_3/src/lib/libcrypto/x509/x509_vpm.c) (`OPENBSD_6_3`), the first release with this export; 2.5.4, the version the debt file names, lacks it, and its layouts are the same as 2.7's: - a non-null name with `namelen` 0 is measured with `strlen`; - a name with a NUL among its `namelen` bytes returns 0 and leaves the host list alone; - otherwise the list is freed (each name, then the stack), and a null or empty name returns 1 with no list; - a non-empty name is copied with the guest `strndup`, as the module would through libc, and pushed on a new plain stack (4 slots, no comparator); a failed copy or stack allocation frees what it allocated and returns 0 with no list. LibreSSL 2.8 also sets a `poisoned` field when the call fails; that field is not in the 2.5.4 to 2.7 parameter identity used here, so a failed call leaves no mark. The debt entry records this. Null verify parameters or identity throw where LibreSSL faults. The pending-export count in `docs/dev/debt/libSceLibreSsl.md` drops by one. This branch stacks on #11105, which carries #11100 and #11089 (#11089, #11100, #11105, then this one). Each branch merges the previous one, so the files they share are resolved once along the chain. ### Tested Debian trixie container, GCC 14.2, full Release build of this branch. `ctest -R 'libressl|crypto_memcmp'`: all pass (18 of 18 on the stacked head). `guest_libressl_x509_store` now also covers this export: terminated and counted names, a counted name without a terminator, an embedded NUL refused with the list kept, null and empty names clearing the list, a name the store frees, and the throwing cases; `guest_libressl_x509_store_allocator` counts the copy, stack and array allocations, the frees when a name replaces another, and a failed copy and a failed stack allocation. `python3 tools/check_conventions.py --base upstream/main` passes. Not tested on Windows, on a title or on a console. `tools/pr_overlap.py` was not run (no authenticated `gh`). ### 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 - [x] Generic behaviour, not specific to one title - [x] Depends on: #11105 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 21:27:27 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed exact head 005afcac1035f73e3b1c6231379d1dee31564204. I compared the callback types, X509_VERIFY_PARAM layout, ex_data pointer, and associated declarations with the pinned LibreSSL OPENBSD_6_3 headers; the PR’s static assertions match those definitions. The namelen == 0 C-string behavior is documented, and I found no implementation defect in the diff. Local convention and whitespace checks pass. I attempted a local configure, but it stopped before compilation because this environment lacks SDL2Config.cmake; therefore I could not independently run the product tests. Hosted eligibility/conventions/intake/labels pass, while product build jobs are not present in this PR’s checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645401104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11189#pullrequestreview-5645401104). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T21:27:27Z. **Review:** COMMENTED --- Reviewed exact head `005afcac1035f73e3b1c6231379d1dee31564204`. I compared the callback types, `X509_VERIFY_PARAM` layout, ex_data pointer, and associated declarations with the pinned LibreSSL OPENBSD_6_3 headers; the PR’s static assertions match those definitions. The `namelen == 0` C-string behavior is documented, and I found no implementation defect in the diff. Local convention and whitespace checks pass. I attempted a local configure, but it stopped before compilation because this environment lacks `SDL2Config.cmake`; therefore I could not independently run the product tests. Hosted eligibility/conventions/intake/labels pass, while product build jobs are not present in this PR’s checks.
MarcZX10 commented 2026-10-25 21:30:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T21:30:40Z.

Review: COMMENTED


Re-reviewed exact current head 25079c78a3f4211089aa70e46e5a0af49d2e76a0 after its merge with upstream/main and #11089. The parent stack matches #11089’s current head 445853269af723060362472e83be8865711fb355; the X509 store implementation is the same code reviewed in that PR, while the new set1_host path still matches the pinned 2.7 host-list behavior and preserves the prior list for embedded-NUL rejection. The debt count was reconciled after the merge. I found no new code issue. The PR reports a Debian trixie Release build and 13/13 focused tests; hosted eligibility, conventions, labels, and report pass, while product jobs are skipped. I did not rerun the runtime suite locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645414146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11189#pullrequestreview-5645414146). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T21:30:40Z. **Review:** COMMENTED --- Re-reviewed exact current head `25079c78a3f4211089aa70e46e5a0af49d2e76a0` after its merge with `upstream/main` and #11089. The parent stack matches #11089’s current head `445853269af723060362472e83be8865711fb355`; the X509 store implementation is the same code reviewed in that PR, while the new `set1_host` path still matches the pinned 2.7 host-list behavior and preserves the prior list for embedded-NUL rejection. The debt count was reconciled after the merge. I found no new code issue. The PR reports a Debian trixie Release build and 13/13 focused tests; hosted eligibility, conventions, labels, and report pass, while product jobs are skipped. I did not rerun the runtime suite locally.
thepoppfish commented 2026-10-25 21:41:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T21:41:27Z.

Review: COMMENTED


Independent native Windows runtime validation of refreshed head 25079c78a3f4211089aa70e46e5a0af49d2e76a0, supplementing the source/layout review above. I found no mismatch in the exercised hostname-setter paths.

Windows 11 build 26200, MSYS2 UCRT64 GCC 16.2.0, C++20 -O1 -g -fno-inline -fno-lto, static C++ runtime. Built the complete production X509Store.cpp, AllocatingStrings.cpp and ApplicationHeap.cpp against this commit's actual headers. The setter, guest strndup, stack cleanup, application-heap registration and callback dispatch are unmodified production code. MinGW unwind sections are renamed after linking as shown below.

External CTest: 4/4 passed, no skips, 0.26 s:

  • The complete committed X509Store test executable in allocator mode, including its existing copy/stack allocation failure assertions.
  • 264 string cases: every single byte 0..255 passed with an explicit count, plus terminated/counted names, embedded NUL rejection, and null/empty clearing. Each checks return value, copied bytes/terminator or preservation of the old list, the verify-parameter/identity bytes outside hosts, and zero tracked guest blocks after actual store destruction. These check storage semantics, not hostname matching or certificate verification.
  • Six allocation-failure cases: failure at copy, stack allocation, and stack-array allocation, each with and without an existing host list. Every case returns 0, leaves hosts null and releases all partial allocations. This includes the third allocation not injected by the committed allocator fixture.
  • One guarded-input case: a nonterminated three-byte name ends exactly at a PAGE_NOACCESS boundary; setting it with count 3 copies and terminates it successfully without reading the inaccessible page.

I first obtained the same 4/4 result at 005afcac1035f73e3b1c6231379d1dee31564204. After your refresh, I verified that all four production/test source files used here are byte-identical and rebuilt/reran against the refreshed checkout and headers, rather than treating the old binary as a current-head test. Conventions against main snapshot 366dd4e6b704b048e05eee65e0edead78352811a and whitespace checks pass; the checkout is clean.

The exercised return/state ordering matches int_x509_param_set_hosts at OPENBSD_6_3: embedded-NUL rejection precedes clearing; SET_HOST clears before copying; allocation failure leaves no new list. I resolved the tag to that commit and verified the pinned source matches the tag. This is a source comparison, not execution of a complete upstream LibreSSL binary or a new console measurement.

Scope/boundaries: the external malloc/calloc/realloc/free wrappers forward to real ApplicationHeap functions and translate allocation exceptions to errno 12/null as the custom-heap path does. The registered test callbacks allocate/free real CRT memory; unused default-heap, process-parameter and formatting paths throw if reached. I did not run the default-heap mode of the full fixture, the full 13-test product/shared-library build, Linux/macOS, a title, or PS5 hardware. No target parser, strndup, registration or cleanup function is mocked.

Comment-only supporting runtime evidence. A canonical overlap scan was started at the old 005afca head before the refresh and is still in progress; it does not establish the current head's overlap status. The declared #11089 dependency and shared-file integration with #11100/#11105 retain their separate coordination requirements. AI-assisted: yes.

Complete external harness and replay

Place review-11189 and native-host11189 beside each other and save the three files below under native-host11189. With Git, MinGW GCC, CMake and Ninja on PATH:

git clone --no-checkout https://github.com/boykopovar/AnyPS5.git review-11189
git -C review-11189 checkout --detach 25079c78a3f4211089aa70e46e5a0af49d2e76a0
cmake -S native-host11189 -B native-host11189/build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build native-host11189/build -j 3
ctest --test-dir native-host11189/build --output-on-failure -V

Only allocator mode of the author fixture is registered; the default GuestHeap adapters deliberately throw. Each test has an eight-second timeout. Probe output from the refreshed-head run:

{"mode":"corpus","cases":264,"live_guest_blocks":0,"failures":0}
{"mode":"faults","cases":6,"live_guest_blocks":0,"failures":0}
{"mode":"guard","cases":1,"live_guest_blocks":0,"failures":0}

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(HostSetterReview LANGUAGES CXX)
get_filename_component(DEFAULT_REPO "${CMAKE_CURRENT_LIST_DIR}/../review-11189" ABSOLUTE)
set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact reviewed checkout")
enable_testing()
foreach(kind IN ITEMS author probe)
    if(kind STREQUAL author)
        set(entry "${REPO}/core/libs/prx/libSceLibreSsl/tests/X509Store.cpp")
    else()
        set(entry "${CMAKE_CURRENT_LIST_DIR}/Probe.cpp")
    endif()
    add_executable(${kind} "${entry}" Support.cpp "${REPO}/core/libs/prx/libSceLibreSsl/src/X509Store.cpp" "${REPO}/core/libs/prx/libc/src/AllocatingStrings.cpp" "${REPO}/core/libs/prx/libc/src/ApplicationHeap.cpp")
    target_compile_features(${kind} PRIVATE cxx_std_20)
    target_compile_options(${kind} PRIVATE -O1 -g -fno-inline -fno-lto -ffunction-sections -fdata-sections)
    target_include_directories(${kind} PRIVATE "${REPO}/core/libs")
    target_link_options(${kind} PRIVATE -static-libstdc++ -static-libgcc -Wl,--gc-sections)
    add_custom_command(TARGET ${kind} POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:${kind}>" VERBATIM)
endforeach()
add_test(NAME author_custom_allocator COMMAND author allocator)
foreach(mode IN ITEMS corpus faults guard)
    add_test(NAME host_${mode} COMMAND probe ${mode})
endforeach()
set_tests_properties(author_custom_allocator host_corpus host_faults host_guard PROPERTIES TIMEOUT 8)

Support.cpp

#include "prx/libc/include/ApplicationHeap.hpp"
#include "prx/libc/include/GuestHeap.hpp"
#include "prx/libc/include/General.hpp"
#include "prx/libc/include/Api.hpp"
#include <cerrno>
#include <new>
#include <stdexcept>

extern "C" void* APS5_VABI malloc_nid_postfix(std::size_t bytes) {
    try { return ApplicationHeapAllocate_nid_no_patch(bytes); }
    catch (const std::bad_alloc&) {}
    catch (const std::length_error&) {}
    errno = 12;
    return nullptr;
}
extern "C" void APS5_VABI free_nid_postfix(void* pointer) { ApplicationHeapFree_nid_no_patch(pointer); }
extern "C" const void* ApplicationProcessParameters_nid_no_patch() { throw std::runtime_error("unexpected process parameter lookup"); }
extern "C" bool ApplicationGuestHeapApi_nid_no_patch(void**) { throw std::runtime_error("unexpected guest API lookup"); }
extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) { throw std::runtime_error(name); }
namespace GuestHeap {
extern "C" std::size_t GuestHeapUsableSize_nid_postfix(const void*) { throw std::runtime_error("unexpected default heap usable size"); }
extern "C" void* GuestHeapAllocate_nid_postfix(std::size_t) { throw std::runtime_error("unexpected default heap allocation"); }
extern "C" void GuestHeapFree_nid_postfix(void*) { throw std::runtime_error("unexpected default heap free"); }
extern "C" void* GuestHeapReallocate_nid_postfix(void*, std::size_t) { throw std::runtime_error("unexpected default heap reallocation"); }
extern "C" void* GuestHeapAlign_nid_postfix(std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap alignment"); }
extern "C" void* GuestHeapRealign_nid_postfix(void*, std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap realignment"); }
extern "C" int GuestHeapStatsFast_nid_postfix(void*) { throw std::runtime_error("unexpected default heap statistics"); }
}

extern "C" void* APS5_VABI calloc_nid_postfix(std::size_t count, std::size_t bytes) {
    try { return ApplicationHeapCalloc_nid_no_patch(count, bytes); }
    catch (const std::bad_alloc&) {}
    catch (const std::length_error&) {}
    errno = 12;
    return nullptr;
}
extern "C" void* APS5_VABI realloc_nid_postfix(void* pointer, std::size_t bytes) {
    try { return ApplicationHeapReallocate_nid_no_patch(pointer, bytes); }
    catch (const std::bad_alloc&) {}
    catch (const std::length_error&) {}
    errno = 12;
    return nullptr;
}
extern "C" int APS5_VABI vasprintf_nid_postfix(char**, const char*, VaList*) { throw std::runtime_error("unexpected formatting path"); }

Probe.cpp

#include "prx/libSceLibreSsl/libSceLibreSsl.hpp"
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/ApplicationHeap.hpp"
#include <array>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stdexcept>
#include <string>
#define NOMINMAX
#include <windows.h>

namespace {
struct Stack {
    std::int32_t num;
    char** data;
    std::int32_t sorted;
    std::int32_t numAlloc;
    int (APS5_VABI* comp)(const void*, const void*);
};
static_assert(sizeof(Stack) == 32);
std::array<void*, 64> blocks{};
int live = 0;
int allocations = 0;
int failAt = -1;
int cases = 0;
void Require(bool condition, const char* message) {
    if (!condition) { std::fprintf(stderr, "%s (case %d, live %d)\n", message, cases, live); std::abort(); }
}
void Track(void* pointer) {
    if (!pointer) return;
    for (auto& slot : blocks) if (!slot) { slot = pointer; ++live; return; }
    std::abort();
}
void* APS5_VABI Allocate(std::size_t bytes) {
    if (++allocations == failAt) return nullptr;
    void* pointer = std::malloc(bytes ? bytes : 1);
    Track(pointer);
    return pointer;
}
void APS5_VABI Free(void* pointer) {
    if (!pointer) return;
    bool found = false;
    for (auto& slot : blocks) if (slot == pointer) { slot = nullptr; --live; found = true; break; }
    Require(found, "free of unknown or already freed block");
    std::free(pointer);
}
void* APS5_VABI Calloc(std::size_t count, std::size_t bytes) {
    void* pointer = std::calloc(count, bytes);
    Track(pointer);
    return pointer;
}
void* APS5_VABI Unexpected() { throw std::runtime_error("unexpected allocator callback"); }
void Initialize() {
    const std::array<void*, 10> api{reinterpret_cast<void*>(Allocate), reinterpret_cast<void*>(Free), reinterpret_cast<void*>(Calloc), reinterpret_cast<void*>(Unexpected), reinterpret_cast<void*>(Unexpected), reinterpret_cast<void*>(Unexpected), reinterpret_cast<void*>(Unexpected)};
    ApplicationHeapRegister_nid_no_patch(api.data());
}
void Case(const char* name, std::size_t length, int expected, const char* copied, std::size_t copiedLength, bool initial = true, int failure = -1) {
    ++cases;
    auto* store = X509_STORE_new_nid_postfix();
    Require(store && live == 7, "store setup allocation count");
    auto* param = store->param;
    param->flags = 0xa5a5a5a5;
    param->id->hostFlags = 0x5a5a5a5a;
    if (initial) Require(X509_VERIFY_PARAM_set1_host_nid_postfix(param, "old.example", 0) == 1, "old hostname setup");
    void* oldHosts = param->id->hosts;
    std::array<unsigned char, sizeof(*param)> paramBefore;
    std::array<unsigned char, sizeof(*param->id)> idBefore;
    std::memcpy(paramBefore.data(), param, paramBefore.size());
    std::memcpy(idBefore.data(), param->id, idBefore.size());
    allocations = 0;
    failAt = failure;
    const int result = X509_VERIFY_PARAM_set1_host_nid_postfix(param, name, length);
    const int calls = allocations;
    failAt = -1;
    Require(result == expected, "setter result");
    if (expected == 0 && failure < 0) {
        Require(param->id->hosts == oldHosts, "invalid name must preserve old stack");
        if (initial) Require(std::strcmp(static_cast<Stack*>(oldHosts)->data[0], "old.example") == 0, "invalid name changed old string");
        Require(calls == 0, "invalid name allocated memory");
        Require(live == (initial ? 10 : 7), "invalid name leaked memory");
    } else if (copied && expected == 1) {
        const auto* stack = static_cast<const Stack*>(param->id->hosts);
        Require(stack && stack->num == 1 && stack->numAlloc == 4 && stack->sorted == 0 && !stack->comp, "new stack shape");
        Require(std::memcmp(stack->data[0], copied, copiedLength) == 0 && stack->data[0][copiedLength] == 0, "counted hostname copy");
        Require(calls == 3 && live == 10, "successful name allocation/leak count");
    } else {
        Require(param->id->hosts == nullptr && live == 7, "clear/failure must leave no list or leaked blocks");
        if (failure >= 1) Require(calls == failure, "wrong allocation failure point");
        else Require(calls == 0, "clearing allocated memory");
    }
    void* saved = param->id->hosts;
    param->id->hosts = oldHosts;
    Require(std::memcmp(paramBefore.data(), param, paramBefore.size()) == 0, "setter changed verify parameter bytes");
    Require(std::memcmp(idBefore.data(), param->id, idBefore.size()) == 0, "setter changed identity bytes outside hosts");
    param->id->hosts = saved;
    X509_STORE_free_nid_postfix(store);
    Require(live == 0, "store/host destruction leaked");
}
void Corpus() {
    for (unsigned int value = 0; value < 256; ++value) {
        const char byte = static_cast<char>(value);
        Case(&byte, 1, value ? 1 : 0, value ? &byte : nullptr, value ? 1 : 0);
    }
    Case("example.com", 0, 1, "example.com", 11);
    Case("www.example.org.extra", 15, 1, "www.example.org", 15);
    const char embedded[] = {'a', 0, 'b'};
    Case(embedded, sizeof embedded, 0, nullptr, 0);
    Case("", 0, 1, nullptr, 0);
    Case(nullptr, 0, 1, nullptr, 0);
    Case(nullptr, 5, 1, nullptr, 0);
    Case("", 0, 1, nullptr, 0, false);
    Case(nullptr, 5, 1, nullptr, 0, false);
}
void Faults() {
    for (bool initial : {false, true})
        for (int position : {1, 2, 3})
            Case("new.example", 0, 0, nullptr, 0, initial, position);
}
void Guard() {
    SYSTEM_INFO system{};
    GetSystemInfo(&system);
    const auto page = static_cast<std::size_t>(system.dwPageSize);
    auto* mapping = static_cast<char*>(VirtualAlloc(nullptr, page * 2, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
    Require(mapping != nullptr, "VirtualAlloc");
    DWORD previous = 0;
    Require(VirtualProtect(mapping + page, page, PAGE_NOACCESS, &previous) != 0, "VirtualProtect");
    auto* name = mapping + page - 3;
    std::memcpy(name, "a.b", 3);
    Case(name, 3, 1, "a.b", 3);
    Require(VirtualFree(mapping, 0, MEM_RELEASE) != 0, "VirtualFree");
}
}
int main(int argc, char** argv) {
    Initialize();
    if (argc != 2) return 2;
    const std::string mode = argv[1];
    if (mode == "corpus") Corpus();
    else if (mode == "faults") Faults();
    else if (mode == "guard") Guard();
    else return 2;
    std::printf("{\"mode\":\"%s\",\"cases\":%d,\"live_guest_blocks\":%d,\"failures\":0}\n", argv[1], cases, live);
    return 0;
}

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645460909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11189#pullrequestreview-5645460909). Originally posted by [thepoppfish](https://github.com/thepoppfish) on 2026-10-25T21:41:27Z. **Review:** COMMENTED --- Independent **native Windows runtime validation** of refreshed head `25079c78a3f4211089aa70e46e5a0af49d2e76a0`, supplementing the source/layout review above. I found no mismatch in the exercised hostname-setter paths. Windows 11 build 26200, MSYS2 UCRT64 GCC 16.2.0, C++20 `-O1 -g -fno-inline -fno-lto`, static C++ runtime. Built the **complete production X509Store.cpp, AllocatingStrings.cpp and ApplicationHeap.cpp** against this commit's actual headers. The setter, guest strndup, stack cleanup, application-heap registration and callback dispatch are unmodified production code. MinGW unwind sections are renamed after linking as shown below. External CTest: **4/4 passed, no skips, 0.26 s**: - The complete committed X509Store test executable in **allocator mode**, including its existing copy/stack allocation failure assertions. - **264 string cases**: every single byte 0..255 passed with an explicit count, plus terminated/counted names, embedded NUL rejection, and null/empty clearing. Each checks return value, copied bytes/terminator or preservation of the old list, the verify-parameter/identity bytes outside `hosts`, and zero tracked guest blocks after actual store destruction. These check storage semantics, not hostname matching or certificate verification. - **Six allocation-failure cases**: failure at copy, stack allocation, and **stack-array allocation**, each with and without an existing host list. Every case returns 0, leaves `hosts` null and releases all partial allocations. This includes the third allocation not injected by the committed allocator fixture. - **One guarded-input case**: a nonterminated three-byte name ends exactly at a PAGE_NOACCESS boundary; setting it with count 3 copies and terminates it successfully without reading the inaccessible page. I first obtained the same 4/4 result at `005afcac1035f73e3b1c6231379d1dee31564204`. After your refresh, I verified that all four production/test source files used here are byte-identical and **rebuilt/reran against the refreshed checkout and headers**, rather than treating the old binary as a current-head test. Conventions against main snapshot `366dd4e6b704b048e05eee65e0edead78352811a` and whitespace checks pass; the checkout is clean. The exercised return/state ordering matches [int_x509_param_set_hosts at OPENBSD_6_3](https://github.com/libressl/openbsd/blob/5044e73fda29e14aa487421b75abb668af034376/src/lib/libcrypto/x509/x509_vpm.c): embedded-NUL rejection precedes clearing; SET_HOST clears before copying; allocation failure leaves no new list. I resolved the tag to that commit and verified the pinned source matches the tag. This is a source comparison, not execution of a complete upstream LibreSSL binary or a new console measurement. Scope/boundaries: the external malloc/calloc/realloc/free wrappers forward to real ApplicationHeap functions and translate allocation exceptions to errno 12/null as the custom-heap path does. The registered test callbacks allocate/free real CRT memory; unused default-heap, process-parameter and formatting paths throw if reached. I did **not** run the default-heap mode of the full fixture, the full 13-test product/shared-library build, Linux/macOS, a title, or PS5 hardware. No target parser, strndup, registration or cleanup function is mocked. Comment-only supporting runtime evidence. A canonical overlap scan was started at the old `005afca` head before the refresh and is still in progress; it does not establish the current head's overlap status. The declared #11089 dependency and shared-file integration with #11100/#11105 retain their separate coordination requirements. AI-assisted: yes. <details> <summary>Complete external harness and replay</summary> Place `review-11189` and `native-host11189` beside each other and save the three files below under native-host11189. With Git, MinGW GCC, CMake and Ninja on PATH: ```powershell git clone --no-checkout https://github.com/boykopovar/AnyPS5.git review-11189 git -C review-11189 checkout --detach 25079c78a3f4211089aa70e46e5a0af49d2e76a0 cmake -S native-host11189 -B native-host11189/build -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build native-host11189/build -j 3 ctest --test-dir native-host11189/build --output-on-failure -V ``` Only allocator mode of the author fixture is registered; the default GuestHeap adapters deliberately throw. Each test has an eight-second timeout. Probe output from the refreshed-head run: ```jsonl {"mode":"corpus","cases":264,"live_guest_blocks":0,"failures":0} {"mode":"faults","cases":6,"live_guest_blocks":0,"failures":0} {"mode":"guard","cases":1,"live_guest_blocks":0,"failures":0} ``` `CMakeLists.txt` ```cmake cmake_minimum_required(VERSION 3.20) project(HostSetterReview LANGUAGES CXX) get_filename_component(DEFAULT_REPO "${CMAKE_CURRENT_LIST_DIR}/../review-11189" ABSOLUTE) set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact reviewed checkout") enable_testing() foreach(kind IN ITEMS author probe) if(kind STREQUAL author) set(entry "${REPO}/core/libs/prx/libSceLibreSsl/tests/X509Store.cpp") else() set(entry "${CMAKE_CURRENT_LIST_DIR}/Probe.cpp") endif() add_executable(${kind} "${entry}" Support.cpp "${REPO}/core/libs/prx/libSceLibreSsl/src/X509Store.cpp" "${REPO}/core/libs/prx/libc/src/AllocatingStrings.cpp" "${REPO}/core/libs/prx/libc/src/ApplicationHeap.cpp") target_compile_features(${kind} PRIVATE cxx_std_20) target_compile_options(${kind} PRIVATE -O1 -g -fno-inline -fno-lto -ffunction-sections -fdata-sections) target_include_directories(${kind} PRIVATE "${REPO}/core/libs") target_link_options(${kind} PRIVATE -static-libstdc++ -static-libgcc -Wl,--gc-sections) add_custom_command(TARGET ${kind} POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:${kind}>" VERBATIM) endforeach() add_test(NAME author_custom_allocator COMMAND author allocator) foreach(mode IN ITEMS corpus faults guard) add_test(NAME host_${mode} COMMAND probe ${mode}) endforeach() set_tests_properties(author_custom_allocator host_corpus host_faults host_guard PROPERTIES TIMEOUT 8) ``` `Support.cpp` ```cpp #include "prx/libc/include/ApplicationHeap.hpp" #include "prx/libc/include/GuestHeap.hpp" #include "prx/libc/include/General.hpp" #include "prx/libc/include/Api.hpp" #include <cerrno> #include <new> #include <stdexcept> extern "C" void* APS5_VABI malloc_nid_postfix(std::size_t bytes) { try { return ApplicationHeapAllocate_nid_no_patch(bytes); } catch (const std::bad_alloc&) {} catch (const std::length_error&) {} errno = 12; return nullptr; } extern "C" void APS5_VABI free_nid_postfix(void* pointer) { ApplicationHeapFree_nid_no_patch(pointer); } extern "C" const void* ApplicationProcessParameters_nid_no_patch() { throw std::runtime_error("unexpected process parameter lookup"); } extern "C" bool ApplicationGuestHeapApi_nid_no_patch(void**) { throw std::runtime_error("unexpected guest API lookup"); } extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) { throw std::runtime_error(name); } namespace GuestHeap { extern "C" std::size_t GuestHeapUsableSize_nid_postfix(const void*) { throw std::runtime_error("unexpected default heap usable size"); } extern "C" void* GuestHeapAllocate_nid_postfix(std::size_t) { throw std::runtime_error("unexpected default heap allocation"); } extern "C" void GuestHeapFree_nid_postfix(void*) { throw std::runtime_error("unexpected default heap free"); } extern "C" void* GuestHeapReallocate_nid_postfix(void*, std::size_t) { throw std::runtime_error("unexpected default heap reallocation"); } extern "C" void* GuestHeapAlign_nid_postfix(std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap alignment"); } extern "C" void* GuestHeapRealign_nid_postfix(void*, std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap realignment"); } extern "C" int GuestHeapStatsFast_nid_postfix(void*) { throw std::runtime_error("unexpected default heap statistics"); } } extern "C" void* APS5_VABI calloc_nid_postfix(std::size_t count, std::size_t bytes) { try { return ApplicationHeapCalloc_nid_no_patch(count, bytes); } catch (const std::bad_alloc&) {} catch (const std::length_error&) {} errno = 12; return nullptr; } extern "C" void* APS5_VABI realloc_nid_postfix(void* pointer, std::size_t bytes) { try { return ApplicationHeapReallocate_nid_no_patch(pointer, bytes); } catch (const std::bad_alloc&) {} catch (const std::length_error&) {} errno = 12; return nullptr; } extern "C" int APS5_VABI vasprintf_nid_postfix(char**, const char*, VaList*) { throw std::runtime_error("unexpected formatting path"); } ``` `Probe.cpp` ```cpp #include "prx/libSceLibreSsl/libSceLibreSsl.hpp" #include "prx/libc/include/Api.hpp" #include "prx/libc/include/ApplicationHeap.hpp" #include <array> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <stdexcept> #include <string> #define NOMINMAX #include <windows.h> namespace { struct Stack { std::int32_t num; char** data; std::int32_t sorted; std::int32_t numAlloc; int (APS5_VABI* comp)(const void*, const void*); }; static_assert(sizeof(Stack) == 32); std::array<void*, 64> blocks{}; int live = 0; int allocations = 0; int failAt = -1; int cases = 0; void Require(bool condition, const char* message) { if (!condition) { std::fprintf(stderr, "%s (case %d, live %d)\n", message, cases, live); std::abort(); } } void Track(void* pointer) { if (!pointer) return; for (auto& slot : blocks) if (!slot) { slot = pointer; ++live; return; } std::abort(); } void* APS5_VABI Allocate(std::size_t bytes) { if (++allocations == failAt) return nullptr; void* pointer = std::malloc(bytes ? bytes : 1); Track(pointer); return pointer; } void APS5_VABI Free(void* pointer) { if (!pointer) return; bool found = false; for (auto& slot : blocks) if (slot == pointer) { slot = nullptr; --live; found = true; break; } Require(found, "free of unknown or already freed block"); std::free(pointer); } void* APS5_VABI Calloc(std::size_t count, std::size_t bytes) { void* pointer = std::calloc(count, bytes); Track(pointer); return pointer; } void* APS5_VABI Unexpected() { throw std::runtime_error("unexpected allocator callback"); } void Initialize() { const std::array<void*, 10> api{reinterpret_cast<void*>(Allocate), reinterpret_cast<void*>(Free), reinterpret_cast<void*>(Calloc), reinterpret_cast<void*>(Unexpected), reinterpret_cast<void*>(Unexpected), reinterpret_cast<void*>(Unexpected), reinterpret_cast<void*>(Unexpected)}; ApplicationHeapRegister_nid_no_patch(api.data()); } void Case(const char* name, std::size_t length, int expected, const char* copied, std::size_t copiedLength, bool initial = true, int failure = -1) { ++cases; auto* store = X509_STORE_new_nid_postfix(); Require(store && live == 7, "store setup allocation count"); auto* param = store->param; param->flags = 0xa5a5a5a5; param->id->hostFlags = 0x5a5a5a5a; if (initial) Require(X509_VERIFY_PARAM_set1_host_nid_postfix(param, "old.example", 0) == 1, "old hostname setup"); void* oldHosts = param->id->hosts; std::array<unsigned char, sizeof(*param)> paramBefore; std::array<unsigned char, sizeof(*param->id)> idBefore; std::memcpy(paramBefore.data(), param, paramBefore.size()); std::memcpy(idBefore.data(), param->id, idBefore.size()); allocations = 0; failAt = failure; const int result = X509_VERIFY_PARAM_set1_host_nid_postfix(param, name, length); const int calls = allocations; failAt = -1; Require(result == expected, "setter result"); if (expected == 0 && failure < 0) { Require(param->id->hosts == oldHosts, "invalid name must preserve old stack"); if (initial) Require(std::strcmp(static_cast<Stack*>(oldHosts)->data[0], "old.example") == 0, "invalid name changed old string"); Require(calls == 0, "invalid name allocated memory"); Require(live == (initial ? 10 : 7), "invalid name leaked memory"); } else if (copied && expected == 1) { const auto* stack = static_cast<const Stack*>(param->id->hosts); Require(stack && stack->num == 1 && stack->numAlloc == 4 && stack->sorted == 0 && !stack->comp, "new stack shape"); Require(std::memcmp(stack->data[0], copied, copiedLength) == 0 && stack->data[0][copiedLength] == 0, "counted hostname copy"); Require(calls == 3 && live == 10, "successful name allocation/leak count"); } else { Require(param->id->hosts == nullptr && live == 7, "clear/failure must leave no list or leaked blocks"); if (failure >= 1) Require(calls == failure, "wrong allocation failure point"); else Require(calls == 0, "clearing allocated memory"); } void* saved = param->id->hosts; param->id->hosts = oldHosts; Require(std::memcmp(paramBefore.data(), param, paramBefore.size()) == 0, "setter changed verify parameter bytes"); Require(std::memcmp(idBefore.data(), param->id, idBefore.size()) == 0, "setter changed identity bytes outside hosts"); param->id->hosts = saved; X509_STORE_free_nid_postfix(store); Require(live == 0, "store/host destruction leaked"); } void Corpus() { for (unsigned int value = 0; value < 256; ++value) { const char byte = static_cast<char>(value); Case(&byte, 1, value ? 1 : 0, value ? &byte : nullptr, value ? 1 : 0); } Case("example.com", 0, 1, "example.com", 11); Case("www.example.org.extra", 15, 1, "www.example.org", 15); const char embedded[] = {'a', 0, 'b'}; Case(embedded, sizeof embedded, 0, nullptr, 0); Case("", 0, 1, nullptr, 0); Case(nullptr, 0, 1, nullptr, 0); Case(nullptr, 5, 1, nullptr, 0); Case("", 0, 1, nullptr, 0, false); Case(nullptr, 5, 1, nullptr, 0, false); } void Faults() { for (bool initial : {false, true}) for (int position : {1, 2, 3}) Case("new.example", 0, 0, nullptr, 0, initial, position); } void Guard() { SYSTEM_INFO system{}; GetSystemInfo(&system); const auto page = static_cast<std::size_t>(system.dwPageSize); auto* mapping = static_cast<char*>(VirtualAlloc(nullptr, page * 2, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require(mapping != nullptr, "VirtualAlloc"); DWORD previous = 0; Require(VirtualProtect(mapping + page, page, PAGE_NOACCESS, &previous) != 0, "VirtualProtect"); auto* name = mapping + page - 3; std::memcpy(name, "a.b", 3); Case(name, 3, 1, "a.b", 3); Require(VirtualFree(mapping, 0, MEM_RELEASE) != 0, "VirtualFree"); } } int main(int argc, char** argv) { Initialize(); if (argc != 2) return 2; const std::string mode = argv[1]; if (mode == "corpus") Corpus(); else if (mode == "faults") Faults(); else if (mode == "guard") Guard(); else return 2; std::printf("{\"mode\":\"%s\",\"cases\":%d,\"live_guest_blocks\":%d,\"failures\":0}\n", argv[1], cases, live); return 0; } ``` </details>
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!11189
No description provided.