summaryrefslogtreecommitdiffstats
path: root/Modules/faulthandler.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-03-03 23:25:03 (GMT)
committerGitHub <noreply@github.com>2022-03-03 23:25:03 (GMT)
commit65b92ccdec2ee4a99e54aaf7ae2d9bbc2ebfe549 (patch)
treea43d4b743ada236f635900000b9f0d689413f8cd /Modules/faulthandler.c
parent32f0c8271706550096c454eb512450b85fbfc320 (diff)
downloadcpython-65b92ccdec2ee4a99e54aaf7ae2d9bbc2ebfe549.zip
cpython-65b92ccdec2ee4a99e54aaf7ae2d9bbc2ebfe549.tar.gz
cpython-65b92ccdec2ee4a99e54aaf7ae2d9bbc2ebfe549.tar.bz2
bpo-46913: Fix test_faulthandler.test_read_null() on UBSan (GH31672)
Disable undefined behavior sanitizer (UBSan) on faulthandler._read_null().
Diffstat (limited to 'Modules/faulthandler.c')
-rw-r--r--Modules/faulthandler.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 4f9f661..db3f4fb 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -32,6 +32,23 @@
#define PUTS(fd, str) _Py_write_noraise(fd, str, strlen(str))
+
+// clang uses __attribute__((no_sanitize("undefined")))
+// GCC 4.9+ uses __attribute__((no_sanitize_undefined))
+#if defined(__has_feature) // Clang
+# if __has_feature(undefined_behavior_sanitizer)
+# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
+# endif
+#endif
+#if defined(__GNUC__) \
+ && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))
+# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
+#endif
+#ifndef _Py_NO_SANITIZE_UNDEFINED
+# define _Py_NO_SANITIZE_UNDEFINED
+#endif
+
+
#ifdef HAVE_SIGACTION
typedef struct sigaction _Py_sighandler_t;
#else
@@ -1013,7 +1030,7 @@ faulthandler_suppress_crash_report(void)
#endif
}
-static PyObject *
+static PyObject* _Py_NO_SANITIZE_UNDEFINED
faulthandler_read_null(PyObject *self, PyObject *args)
{
volatile int *x;
@@ -1102,21 +1119,6 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-// clang uses __attribute__((no_sanitize("undefined")))
-// GCC 4.9+ uses __attribute__((no_sanitize_undefined))
-#if defined(__has_feature) // Clang
-# if __has_feature(undefined_behavior_sanitizer)
-# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
-# endif
-#endif
-#if defined(__GNUC__) \
- && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))
-# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
-#endif
-#ifndef _Py_NO_SANITIZE_UNDEFINED
-# define _Py_NO_SANITIZE_UNDEFINED
-#endif
-
static PyObject* _Py_NO_SANITIZE_UNDEFINED
faulthandler_sigfpe(PyObject *self, PyObject *args)
{