From 01072bfe9700f964ad70c7c576f36863cb4e238b Mon Sep 17 00:00:00 2001 From: QRMOE Date: Sat, 10 Oct 2026 16:32:37 +0200 Subject: [PATCH] test(libc): require a stable guest hostname AI-assisted: yes. Verify AnyPS5 rather than the native PC hostname. Cover buffer capacities, guard bytes, maximum size_t capacity, null queries, success errno and thread-local isolation. The old implementation fails this regression; the final fixed tree passes the complete Windows build and five repeated runs each of guest_hostname and guest_errors on main 5edae3536. Linux and title tests of this new revision are pending. --- core/libs/tests/GuestHostname.cpp | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/core/libs/tests/GuestHostname.cpp b/core/libs/tests/GuestHostname.cpp index bc76129ab..36e18845d 100644 --- a/core/libs/tests/GuestHostname.cpp +++ b/core/libs/tests/GuestHostname.cpp @@ -3,14 +3,10 @@ #include #include #include -#include +#include +#include #include #include -#ifdef _WIN32 -#include -#else -#include -#endif extern "C" { int APS5_VABI gethostname_nid_postfix(char*, std::size_t); @@ -26,15 +22,7 @@ static void Require(bool condition, int line) { #define Check(value) Require((value), __LINE__) int main() { - std::array native{}; -#ifdef _WIN32 - DWORD size = native.size(); - Check(GetComputerNameExA(ComputerNameDnsHostname, native.data(), &size)); -#else - Check(::gethostname(native.data(), native.size()) == 0); -#endif - const std::string expected = native.data(); - Check(!expected.empty()); + constexpr std::string_view expected = "AnyPS5"; for (std::size_t length = 0; length <= expected.size() + 2; ++length) { std::vector buffer(length + 2, '#'); *__error_nid_postfix() = 71; @@ -45,17 +33,27 @@ int main() { Check(std::memcmp(buffer.data() + 1, expected.data(), length) == 0); } else { Check(result == 0 && *__error_nid_postfix() == 71); - Check(std::strcmp(buffer.data() + 1, expected.c_str()) == 0); + Check(std::strcmp(buffer.data() + 1, expected.data()) == 0); for (std::size_t index = expected.size() + 2; index < buffer.size(); ++index) Check(buffer[index] == '#'); } } + std::array oversized; + oversized.fill('#'); + *__error_nid_postfix() = 71; + Check(gethostname_nid_postfix(oversized.data() + 1, std::numeric_limits::max()) == 0); + Check(*__error_nid_postfix() == 71); + Check(std::strcmp(oversized.data() + 1, expected.data()) == 0); + Check(oversized.front() == '#' && oversized.back() == '#'); *__error_nid_postfix() = 22; Check(gethostname_nid_postfix(nullptr, 0) == 0 && *__error_nid_postfix() == 22); Check(gethostname_nid_postfix(nullptr, 1024) == 0 && *__error_nid_postfix() == 22); - std::thread worker([] { + std::thread worker([expected] { char byte = '#'; *__error_nid_postfix() = 0; Check(gethostname_nid_postfix(&byte, 0) == -1 && *__error_nid_postfix() == 63 && byte == '#'); + std::array name{}; + Check(gethostname_nid_postfix(name.data(), name.size()) == 0); + Check(std::strcmp(name.data(), expected.data()) == 0 && *__error_nid_postfix() == 63); }); worker.join(); Check(*__error_nid_postfix() == 22);