From 6fa3e38e5c26820396d11a5a155fc83790d17c72 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 17 Feb 2020 14:15:02 -0500 Subject: Restore SIGILL handler if sigprocmask fails We've never encountered this case, but better safe then sorry. --- cpu.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cpu.cpp') diff --git a/cpu.cpp b/cpu.cpp index 95561742..da9f298c 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -72,9 +72,8 @@ extern "C" { extern "C" { static jmp_buf s_jmpNoCPUID; - static void SigIllHandlerCPUID(int unused) + static void SigIllHandler(int) { - CRYPTOPP_UNUSED(unused); longjmp(s_jmpNoCPUID, 1); } } @@ -358,14 +357,17 @@ bool CpuId(word32 func, word32 subfunc, word32 output[4]) // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true; - volatile SigHandler oldHandler = signal(SIGILL, SigIllHandlerCPUID); + volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler); if (oldHandler == SIG_ERR) return false; # ifndef __MINGW32__ volatile sigset_t oldMask; if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask) != 0) + { + signal(SIGILL, oldHandler); return false; + } # endif if (setjmp(s_jmpNoCPUID)) -- cgit v1.2.1