bpo-41094: Fix decoding errors with audit when open files. (GH-21095)

This commit is contained in:
Serhiy Storchaka 2020-06-24 08:46:05 +03:00 committed by GitHub
parent bf2e515fa4
commit 6c6810d989
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 14 deletions

View file

@ -1415,15 +1415,12 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args)
if (name != Py_None) {
if (PyUnicode_FSConverter(name, &name2) == 0)
return NULL;
if (PyBytes_Check(name2))
name_str = PyBytes_AS_STRING(name2);
else
name_str = PyByteArray_AS_STRING(name2);
name_str = PyBytes_AS_STRING(name2);
} else {
name_str = NULL;
name2 = NULL;
}
if (PySys_Audit("ctypes.dlopen", "s", name_str) < 0) {
if (PySys_Audit("ctypes.dlopen", "O", name) < 0) {
return NULL;
}
handle = ctypes_dlopen(name_str, mode);

View file

@ -379,13 +379,20 @@ pymain_run_startup(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
if (startup == NULL) {
return 0;
}
if (PySys_Audit("cpython.run_startup", "s", startup) < 0) {
PyObject *startup_obj = PyUnicode_DecodeFSDefault(startup);
if (startup_obj == NULL) {
return pymain_err_print(exitcode);
}
if (PySys_Audit("cpython.run_startup", "O", startup_obj) < 0) {
Py_DECREF(startup_obj);
return pymain_err_print(exitcode);
}
Py_DECREF(startup_obj);
FILE *fp = _Py_fopen(startup, "r");
if (fp == NULL) {
int save_errno = errno;
PyErr_Clear();
PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
errno = save_errno;