diff options
author | Alexey Izbyshev <izbyshev@ispras.ru> | 2018-10-20 00:28:22 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2018-10-20 00:28:22 (GMT) |
commit | 834603112e6ca35944dd21105b01fca562dc3241 (patch) | |
tree | 9f4b6f18381528cba38610d214c4422572e572bc /Modules | |
parent | a2670565d8f5c502388378aba1fe73023fd8c8d4 (diff) | |
download | cpython-834603112e6ca35944dd21105b01fca562dc3241.zip cpython-834603112e6ca35944dd21105b01fca562dc3241.tar.gz cpython-834603112e6ca35944dd21105b01fca562dc3241.tar.bz2 |
bpo-32890, os: Use errno instead of GetLastError() in execve() and truncate() (GH-5784)
path_error() uses GetLastError() on Windows, but some os functions
are implemented via CRT APIs which report errors via errno.
This may result in raising OSError with invalid error code (such
as zero).
Introduce posix_path_error() function and use it where appropriate.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 23552be..9ccdc8e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1456,13 +1456,19 @@ win32_error_object(const char* function, PyObject* filename) #endif /* MS_WINDOWS */ static PyObject * +posix_path_object_error(PyObject *path) +{ + return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); +} + +static PyObject * path_object_error(PyObject *path) { #ifdef MS_WINDOWS return PyErr_SetExcFromWindowsErrWithFilenameObject( PyExc_OSError, 0, path); #else - return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); + return posix_path_object_error(path); #endif } @@ -1484,6 +1490,12 @@ path_error(path_t *path) } static PyObject * +posix_path_error(path_t *path) +{ + return posix_path_object_error(path->object); +} + +static PyObject * path_error2(path_t *path, path_t *path2) { return path_object_error2(path->object, path2->object); @@ -5141,7 +5153,7 @@ os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env) /* If we get here it's definitely an error */ - path_error(path); + posix_path_error(path); free_string_array(envlist, envc); fail: @@ -9477,7 +9489,7 @@ os_truncate_impl(PyObject *module, path_t *path, Py_off_t length) _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS if (result < 0) - return path_error(path); + return posix_path_error(path); Py_RETURN_NONE; } |