]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133157: remove usage of `_Py_NO_SANITIZE_UNDEFINED` in `faulthandler` (#134047)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sun, 18 May 2025 08:16:10 +0000 (10:16 +0200)
committerGitHub <noreply@github.com>
Sun, 18 May 2025 08:16:10 +0000 (10:16 +0200)
In `faulthandler_sigfpe()`, instead of using 1/0 arithmetic, we explicitly raise SIGFPE.
We also remove `faulthandler._read_null()` since reading from NULL is an undefined
behavior and `faulthandler` should not check for low-level C undefined behaviors.

Lib/test/test_faulthandler.py
Modules/faulthandler.c

index 371c63adce94123967a7a2ee8f1e5d4b48712e17..2fb963f52e513887b7c0d44a2ccd294760cb9b94 100644 (file)
@@ -166,29 +166,6 @@ class FaultHandlerTests(unittest.TestCase):
         fatal_error = 'Windows fatal exception: %s' % name_regex
         self.check_error(code, line_number, fatal_error, **kw)
 
-    @unittest.skipIf(sys.platform.startswith('aix'),
-                     "the first page of memory is a mapped read-only on AIX")
-    def test_read_null(self):
-        if not MS_WINDOWS:
-            self.check_fatal_error("""
-                import faulthandler
-                faulthandler.enable()
-                faulthandler._read_null()
-                """,
-                3,
-                # Issue #12700: Read NULL raises SIGILL on Mac OS X Lion
-                '(?:Segmentation fault'
-                    '|Bus error'
-                    '|Illegal instruction)')
-        else:
-            self.check_windows_exception("""
-                import faulthandler
-                faulthandler.enable()
-                faulthandler._read_null()
-                """,
-                3,
-                'access violation')
-
     @skip_segfault_on_android
     def test_sigsegv(self):
         self.check_fatal_error("""
index d49ce794d886745ea519ca4a44e4506f08d73d6c..c94f4f66366170a5c6dc7d391a855458f6ff26fe 100644 (file)
@@ -1069,18 +1069,6 @@ faulthandler_suppress_crash_report(void)
 #endif
 }
 
-static PyObject* _Py_NO_SANITIZE_UNDEFINED
-faulthandler_read_null(PyObject *self, PyObject *args)
-{
-    volatile int *x;
-    volatile int y;
-
-    faulthandler_suppress_crash_report();
-    x = NULL;
-    y = *x;
-    return PyLong_FromLong(y);
-
-}
 
 static void
 faulthandler_raise_sigsegv(void)
@@ -1158,23 +1146,12 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
-static PyObject* _Py_NO_SANITIZE_UNDEFINED
+static PyObject*
 faulthandler_sigfpe(PyObject *self, PyObject *Py_UNUSED(dummy))
 {
     faulthandler_suppress_crash_report();
-
-    /* Do an integer division by zero: raise a SIGFPE on Intel CPU, but not on
-       PowerPC. Use volatile to disable compile-time optimizations. */
-    volatile int x = 1, y = 0, z;
-    z = x / y;
-
-    /* If the division by zero didn't raise a SIGFPE (e.g. on PowerPC),
-       raise it manually. */
     raise(SIGFPE);
-
-    /* This line is never reached, but we pretend to make something with z
-       to silence a compiler warning. */
-    return PyLong_FromLong(z);
+    Py_UNREACHABLE();
 }
 
 static PyObject *
@@ -1316,10 +1293,6 @@ static PyMethodDef module_methods[] = {
                "Unregister the handler of the signal "
                "'signum' registered by register().")},
 #endif
-    {"_read_null", faulthandler_read_null, METH_NOARGS,
-     PyDoc_STR("_read_null($module, /)\n--\n\n"
-               "Read from NULL, raise "
-               "a SIGSEGV or SIGBUS signal depending on the platform.")},
     {"_sigsegv", faulthandler_sigsegv, METH_VARARGS,
      PyDoc_STR("_sigsegv($module, release_gil=False, /)\n--\n\n"
                "Raise a SIGSEGV signal.")},