Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName #26083

Merged
merged 5 commits into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions Modules/_xxtestfuzz/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
corona10 marked this conversation as resolved.
Show resolved Hide resolved

status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
goto fail;
}
PyConfig_Clear(&config);

return 0;
corona10 marked this conversation as resolved.
Show resolved Hide resolved

fail:
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}

/* Fuzz test interface.
Expand All @@ -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;

Expand Down