From 40d9ff653382c1e5fa92ded8fbd0986dbdc9d276 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 06:42:25 +0900 Subject: [PATCH 1/5] bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName --- Modules/_xxtestfuzz/fuzzer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c index acbf068637b4ea..3e078a7bf9f28f 100644 --- a/Modules/_xxtestfuzz/fuzzer.c +++ b/Modules/_xxtestfuzz/fuzzer.c @@ -411,8 +411,17 @@ int __lsan_is_turned_off(void) { return 1; } int LLVMFuzzerInitialize(int *argc, char ***argv) { + PyConfig config; + PyConfig_InitIsolatedConfig(&config); + PyStatus status; wchar_t* wide_program_name = Py_DecodeLocale(*argv[0], NULL); - Py_SetProgramName(wide_program_name); + status = PyConfig_SetString(&config, &config.program_name, + wide_program_name); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); + } + return 0; } From 0ddd410d8739ce57d41015764cc527fda430c64d Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 07:00:53 +0900 Subject: [PATCH 2/5] bpo-44113: Update --- Modules/_xxtestfuzz/fuzzer.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c index 3e078a7bf9f28f..c9045e579ccf72 100644 --- a/Modules/_xxtestfuzz/fuzzer.c +++ b/Modules/_xxtestfuzz/fuzzer.c @@ -412,17 +412,22 @@ int __lsan_is_turned_off(void) { return 1; } int LLVMFuzzerInitialize(int *argc, char ***argv) { PyConfig config; - PyConfig_InitIsolatedConfig(&config); + PyConfig_InitPythonConfig(&config); PyStatus status; - wchar_t* wide_program_name = Py_DecodeLocale(*argv[0], NULL); - status = PyConfig_SetString(&config, &config.program_name, - wide_program_name); + status = PyConfig_SetBytesString(&config, &config.program_name, *argv[0]); if (PyStatus_Exception(status)) { - PyConfig_Clear(&config); - Py_ExitStatusException(status); + goto fail; } + status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + goto fail; + } + PyConfig_Clear(&config); return 0; +fail: + PyConfig_Clear(&config); + Py_ExitStatusException(status); } /* Fuzz test interface. @@ -433,13 +438,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) { (And we bitwise or when running multiple tests to verify that normally we only return 0.) */ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - if (!Py_IsInitialized()) { - /* LLVMFuzzerTestOneInput is called repeatedly from the same process, - with no separate initialization phase, sadly, so we need to - initialize CPython ourselves on the first run. */ - Py_InitializeEx(0); - } - int rv = 0; #if !defined(_Py_FUZZ_ONE) || defined(_Py_FUZZ_fuzz_builtin_float) From acab08b2a916cd4868e6430527d0e2b04c62e5df Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 07:18:46 +0900 Subject: [PATCH 3/5] bpo-44113: Add assert --- Modules/_xxtestfuzz/fuzzer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c index c9045e579ccf72..892b3a04856dd8 100644 --- a/Modules/_xxtestfuzz/fuzzer.c +++ b/Modules/_xxtestfuzz/fuzzer.c @@ -438,6 +438,8 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) { (And we bitwise or when running multiple tests to verify that normally we only return 0.) */ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + assert(Py_IsInitialized()); + int rv = 0; #if !defined(_Py_FUZZ_ONE) || defined(_Py_FUZZ_fuzz_builtin_float) From ed2cd4e5ae79ef2c22de5ed0e932ea46e59736d8 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 07:21:26 +0900 Subject: [PATCH 4/5] bpo-44113: Set config.install_signal_handlers = 0 --- Modules/_xxtestfuzz/fuzzer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c index 892b3a04856dd8..9a96a942ab832e 100644 --- a/Modules/_xxtestfuzz/fuzzer.c +++ b/Modules/_xxtestfuzz/fuzzer.c @@ -413,6 +413,7 @@ int __lsan_is_turned_off(void) { return 1; } int LLVMFuzzerInitialize(int *argc, char ***argv) { PyConfig config; PyConfig_InitPythonConfig(&config); + config.install_signal_handlers = 0; PyStatus status; status = PyConfig_SetBytesString(&config, &config.program_name, *argv[0]); if (PyStatus_Exception(status)) { From 83bd5d8d0f192b086e29e69d449e17c49ff5cd4d Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 07:57:42 +0900 Subject: [PATCH 5/5] bpo-44113: Add empty line --- Modules/_xxtestfuzz/fuzzer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c index 9a96a942ab832e..e1256f59cc9c28 100644 --- a/Modules/_xxtestfuzz/fuzzer.c +++ b/Modules/_xxtestfuzz/fuzzer.c @@ -425,7 +425,9 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) { goto fail; } PyConfig_Clear(&config); + return 0; + fail: PyConfig_Clear(&config); Py_ExitStatusException(status);