]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName (GH-26083)
authorDong-hee Na <donghee.na@python.org>
Wed, 12 May 2021 23:22:18 +0000 (08:22 +0900)
committerGitHub <noreply@github.com>
Wed, 12 May 2021 23:22:18 +0000 (08:22 +0900)
Modules/_xxtestfuzz/fuzzer.c

index acbf068637b4eaef8de329dc68a109fe7e769950..e1256f59cc9c287ce029e223bc8e894082a8c47e 100644 (file)
@@ -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;