bpo-38020: Fixes crash in os.readlink() on Windows (GH-15663)

This commit is contained in:
Steve Dower 2019-09-03 12:50:51 -07:00 committed by GitHub
parent 0cf832a9ef
commit 993ac92418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Fixes potential crash when calling :func:`os.readlink` (or indirectly
through :func:`~os.path.realpath`) on a file that is not a supported link.

View File

@ -7818,7 +7818,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
HANDLE reparse_point_handle;
char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
_Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
PyObject *result;
PyObject *result = NULL;
/* First get a handle to the reparse point */
Py_BEGIN_ALLOW_THREADS
@ -7872,7 +7872,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
name[1] = L'\\';
}
result = PyUnicode_FromWideChar(name, nameLen);
if (path->narrow) {
if (result && path->narrow) {
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
}
}