Skip to content

Commit 54dac6c

Browse files
bpo-38020: Fixes crash in os.readlink() on Windows (GH-15663)
(cherry picked from commit 993ac92) Co-authored-by: Steve Dower <[email protected]>
1 parent 59e8fba commit 54dac6c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes potential crash when calling :func:`os.readlink` (or indirectly
2+
through :func:`~os.path.realpath`) on a file that is not a supported link.

Modules/posixmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7821,7 +7821,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
78217821
HANDLE reparse_point_handle;
78227822
char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
78237823
_Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
7824-
PyObject *result;
7824+
PyObject *result = NULL;
78257825

78267826
/* First get a handle to the reparse point */
78277827
Py_BEGIN_ALLOW_THREADS
@@ -7875,7 +7875,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
78757875
name[1] = L'\\';
78767876
}
78777877
result = PyUnicode_FromWideChar(name, nameLen);
7878-
if (path->narrow) {
7878+
if (result && path->narrow) {
78797879
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
78807880
}
78817881
}

0 commit comments

Comments
 (0)