summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-24 16:45:38 (GMT)
committerGitHub <noreply@github.com>2020-06-24 16:45:38 (GMT)
commit1813d318fd4e517042415fa4f59fe8668c17a235 (patch)
tree0641b3dab4350db252cc85bfc5177e494a66e87a /Python
parentfb4a6241054ad6b7f24d1b32af6827e02936d568 (diff)
downloadcpython-1813d318fd4e517042415fa4f59fe8668c17a235.zip
cpython-1813d318fd4e517042415fa4f59fe8668c17a235.tar.gz
cpython-1813d318fd4e517042415fa4f59fe8668c17a235.tar.bz2
bpo-41094: Fix decoding errors with audit when open files. (GH-21095)
(cherry picked from commit 6c6810d98979add7a89391c3c38990d0859f7a29) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/fileutils.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 1021ddb..b274116 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1274,7 +1274,12 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
#endif
if (gil_held) {
- if (PySys_Audit("open", "sOi", pathname, Py_None, flags) < 0) {
+ PyObject *pathname_obj = PyUnicode_DecodeFSDefault(pathname);
+ if (pathname_obj == NULL) {
+ return -1;
+ }
+ if (PySys_Audit("open", "OOi", pathname_obj, Py_None, flags) < 0) {
+ Py_DECREF(pathname_obj);
return -1;
}
@@ -1284,12 +1289,16 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
Py_END_ALLOW_THREADS
} while (fd < 0
&& errno == EINTR && !(async_err = PyErr_CheckSignals()));
- if (async_err)
+ if (async_err) {
+ Py_DECREF(pathname_obj);
return -1;
+ }
if (fd < 0) {
- PyErr_SetFromErrnoWithFilename(PyExc_OSError, pathname);
+ PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, pathname_obj, NULL);
+ Py_DECREF(pathname_obj);
return -1;
}
+ Py_DECREF(pathname_obj);
}
else {
fd = open(pathname, flags);
@@ -1385,9 +1394,15 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode)
FILE*
_Py_fopen(const char *pathname, const char *mode)
{
- if (PySys_Audit("open", "ssi", pathname, mode, 0) < 0) {
+ PyObject *pathname_obj = PyUnicode_DecodeFSDefault(pathname);
+ if (pathname_obj == NULL) {
+ return NULL;
+ }
+ if (PySys_Audit("open", "Osi", pathname_obj, mode, 0) < 0) {
+ Py_DECREF(pathname_obj);
return NULL;
}
+ Py_DECREF(pathname_obj);
FILE *f = fopen(pathname, mode);
if (f == NULL)