Skip to content

Commit 65b92cc

Browse files
authored
bpo-46913: Fix test_faulthandler.test_read_null() on UBSan (GH31672)
Disable undefined behavior sanitizer (UBSan) on faulthandler._read_null().
1 parent 32f0c82 commit 65b92cc

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Modules/faulthandler.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@
3232

3333
#define PUTS(fd, str) _Py_write_noraise(fd, str, strlen(str))
3434

35+
36+
// clang uses __attribute__((no_sanitize("undefined")))
37+
// GCC 4.9+ uses __attribute__((no_sanitize_undefined))
38+
#if defined(__has_feature) // Clang
39+
# if __has_feature(undefined_behavior_sanitizer)
40+
# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
41+
# endif
42+
#endif
43+
#if defined(__GNUC__) \
44+
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))
45+
# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
46+
#endif
47+
#ifndef _Py_NO_SANITIZE_UNDEFINED
48+
# define _Py_NO_SANITIZE_UNDEFINED
49+
#endif
50+
51+
3552
#ifdef HAVE_SIGACTION
3653
typedef struct sigaction _Py_sighandler_t;
3754
#else
@@ -1013,7 +1030,7 @@ faulthandler_suppress_crash_report(void)
10131030
#endif
10141031
}
10151032

1016-
static PyObject *
1033+
static PyObject* _Py_NO_SANITIZE_UNDEFINED
10171034
faulthandler_read_null(PyObject *self, PyObject *args)
10181035
{
10191036
volatile int *x;
@@ -1102,21 +1119,6 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
11021119
Py_RETURN_NONE;
11031120
}
11041121

1105-
// clang uses __attribute__((no_sanitize("undefined")))
1106-
// GCC 4.9+ uses __attribute__((no_sanitize_undefined))
1107-
#if defined(__has_feature) // Clang
1108-
# if __has_feature(undefined_behavior_sanitizer)
1109-
# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
1110-
# endif
1111-
#endif
1112-
#if defined(__GNUC__) \
1113-
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))
1114-
# define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
1115-
#endif
1116-
#ifndef _Py_NO_SANITIZE_UNDEFINED
1117-
# define _Py_NO_SANITIZE_UNDEFINED
1118-
#endif
1119-
11201122
static PyObject* _Py_NO_SANITIZE_UNDEFINED
11211123
faulthandler_sigfpe(PyObject *self, PyObject *args)
11221124
{

0 commit comments

Comments
 (0)