[Python-checkins] bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName (GH-26083)

corona10 webhook-mailer at python.org
Wed May 12 19:22:35 EDT 2021


https://github.com/python/cpython/commit/a0ccc404ca649c2a1635511a09df2454e47b4d66
commit: a0ccc404ca649c2a1635511a09df2454e47b4d66
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2021-05-13T08:22:18+09:00
summary:

bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName (GH-26083)

files:
M Modules/_xxtestfuzz/fuzzer.c

diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c
index acbf068637b4ea..e1256f59cc9c28 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;
 



More information about the Python-checkins mailing list