summaryrefslogtreecommitdiffstats
path: root/Modules/_xxtestfuzz
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2024-02-07 22:21:33 (GMT)
committerGitHub <noreply@github.com>2024-02-07 22:21:33 (GMT)
commit38b970dfcc3cdebc87a456f17ef1e0f06dde7375 (patch)
tree08a0f222a13881a7203bbcaefbd7acdc4662e1d3 /Modules/_xxtestfuzz
parent8f0998e844c2fd8c0c94681d0a6331c34ee31562 (diff)
downloadcpython-38b970dfcc3cdebc87a456f17ef1e0f06dde7375.zip
cpython-38b970dfcc3cdebc87a456f17ef1e0f06dde7375.tar.gz
cpython-38b970dfcc3cdebc87a456f17ef1e0f06dde7375.tar.bz2
When the Py_CompileStringExFlags fuzzer encounters a SystemError, abort (#115147)
This allows us to catch bugs beyond memory corruption and assertions.
Diffstat (limited to 'Modules/_xxtestfuzz')
-rw-r--r--Modules/_xxtestfuzz/fuzzer.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c
index e133b4d..6ea9f64 100644
--- a/Modules/_xxtestfuzz/fuzzer.c
+++ b/Modules/_xxtestfuzz/fuzzer.c
@@ -502,7 +502,6 @@ static int fuzz_elementtree_parsewhole(const char* data, size_t size) {
}
#define MAX_PYCOMPILE_TEST_SIZE 16384
-static char pycompile_scratch[MAX_PYCOMPILE_TEST_SIZE];
static const int start_vals[] = {Py_eval_input, Py_single_input, Py_file_input};
const size_t NUM_START_VALS = sizeof(start_vals) / sizeof(start_vals[0]);
@@ -531,6 +530,8 @@ static int fuzz_pycompile(const char* data, size_t size) {
unsigned char optimize_idx = (unsigned char) data[1];
int optimize = optimize_vals[optimize_idx % NUM_OPTIMIZE_VALS];
+ char pycompile_scratch[MAX_PYCOMPILE_TEST_SIZE];
+
// Create a NUL-terminated C string from the remaining input
memcpy(pycompile_scratch, data + 2, size - 2);
// Put a NUL terminator just after the copied data. (Space was reserved already.)
@@ -549,7 +550,13 @@ static int fuzz_pycompile(const char* data, size_t size) {
PyObject *result = Py_CompileStringExFlags(pycompile_scratch, "<fuzz input>", start, flags, optimize);
if (result == NULL) {
- /* compilation failed, most likely from a syntax error */
+ /* Compilation failed, most likely from a syntax error. If it was a
+ SystemError we abort. There's no non-bug reason to raise a
+ SystemError. */
+ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemError)) {
+ PyErr_Print();
+ abort();
+ }
PyErr_Clear();
} else {
Py_DECREF(result);