From 73f0c5ed78d16f5fd2141c7f573f75432a84cea5 Mon Sep 17 00:00:00 2001 From: EylonKrause Date: Thu, 2 Jul 2026 01:09:34 +0300 Subject: [PATCH] hwcaps: don't return an uninitialized hwcap on elf_aux_info failure On FreeBSD/OpenBSD, GetElfHwcapFromElfAuxInfo left `hwcap` uninitialized and ignored the elf_aux_info() return value. elf_aux_info() only writes the output buffer on success; when the requested entry is absent (e.g. AT_HWCAP2, which CpuFeatures_GetHardwareCapabilities requests unconditionally, on arch/kernel combinations that lack it) it returns non-zero and leaves the buffer untouched, so the function returned an indeterminate stack value that is then bit-tested for CPU features. Initialize to 0 and return 0 on failure, matching the Linux getauxval path. --- src/hwcaps_freebsd_or_openbsd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hwcaps_freebsd_or_openbsd.c b/src/hwcaps_freebsd_or_openbsd.c index db90297c..73a0b137 100644 --- a/src/hwcaps_freebsd_or_openbsd.c +++ b/src/hwcaps_freebsd_or_openbsd.c @@ -30,8 +30,11 @@ const char* CpuFeatures_GetBasePlatformPointer(void); #include static unsigned long GetElfHwcapFromElfAuxInfo(int hwcap_type) { - unsigned long hwcap; - elf_aux_info(hwcap_type, &hwcap, sizeof(hwcap)); + unsigned long hwcap = 0; + // elf_aux_info() leaves the output buffer untouched and returns non-zero when + // the requested entry is absent (e.g. AT_HWCAP2 on some arch/kernel combos), + // so return 0 instead of an indeterminate value. + if (elf_aux_info(hwcap_type, &hwcap, sizeof(hwcap)) != 0) return 0; return hwcap; }