From 4b6a1feab0cf578b68965600a3a91492a72ec8f1 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 1 Oct 2026 02:52:45 -0400 Subject: [PATCH] hwcaps: check elf_aux_info() return value in GetElfHwcapFromElfAuxInfo Do not rely on elf_aux_info() leaving the output buffer untouched on failure, since that is not part of its documented contract. Check the return value and set hwcap to 0 on error. --- src/hwcaps_freebsd_or_openbsd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hwcaps_freebsd_or_openbsd.c b/src/hwcaps_freebsd_or_openbsd.c index 775afe74..e44cc255 100644 --- a/src/hwcaps_freebsd_or_openbsd.c +++ b/src/hwcaps_freebsd_or_openbsd.c @@ -30,11 +30,10 @@ const char* CpuFeatures_GetBasePlatformPointer(void); #include static unsigned long GetElfHwcapFromElfAuxInfo(int hwcap_type) { - unsigned long hwcap = 0; - // elf_aux_info() leaves the output buffer untouched when the requested entry - // is absent (e.g. AT_HWCAP2 on some arch/kernel combos), so initializing - // hwcap to 0 avoids returning an indeterminate value on failure. - elf_aux_info(hwcap_type, &hwcap, sizeof(hwcap)); + unsigned long hwcap; + if (elf_aux_info(hwcap_type, &hwcap, sizeof(hwcap)) != 0) { + hwcap = 0; + } return hwcap; }