Skip to content

Commit cda4f30

Browse files
zoobawebsurfer5
authored andcommitted
bpo-38020: Fixes crash in os.readlink() on Windows (pythonGH-15663)
1 parent 69d15fc commit cda4f30

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
@@ -7818,7 +7818,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
78187818
HANDLE reparse_point_handle;
78197819
char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
78207820
_Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
7821-
PyObject *result;
7821+
PyObject *result = NULL;
78227822

78237823
/* First get a handle to the reparse point */
78247824
Py_BEGIN_ALLOW_THREADS
@@ -7872,7 +7872,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
78727872
name[1] = L'\\';
78737873
}
78747874
result = PyUnicode_FromWideChar(name, nameLen);
7875-
if (path->narrow) {
7875+
if (result && path->narrow) {
78767876
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
78777877
}
78787878
}

0 commit comments

Comments
 (0)