From a0ccc404ca649c2a1635511a09df2454e47b4d66 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 08:22:18 +0900 Subject: bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName (GH-26083) --- Modules/_xxtestfuzz/fuzzer.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c index acbf068..e1256f5 100644 --- a/Modules/_xxtestfuzz/fuzzer.c +++ b/Modules/_xxtestfuzz/fuzzer.c @@ -411,9 +411,26 @@ int __lsan_is_turned_off(void) { return 1; } int LLVMFuzzerInitialize(int *argc, char ***argv) { - wchar_t* wide_program_name = Py_DecodeLocale(*argv[0], NULL); - Py_SetProgramName(wide_program_name); + 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)) { + 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. @@ -424,12 +441,7 @@ 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); - } + assert(Py_IsInitialized()); int rv = 0; -- cgit v0.12