Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3b20d345
Commit
3b20d345
authored
Mar 08, 2018
by
Alexey Izbyshev
Committed by
Steve Dower
Mar 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33016: Fix potential use of uninitialized memory in nt._getfinalpathname (#6010)
parent
3c7ac7ea
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
42 deletions
+33
-42
Misc/NEWS.d/next/Windows/2018-03-07-01-33-33.bpo-33016.Z_Med0.rst
...S.d/next/Windows/2018-03-07-01-33-33.bpo-33016.Z_Med0.rst
+1
-0
Modules/posixmodule.c
Modules/posixmodule.c
+32
-42
No files found.
Misc/NEWS.d/next/Windows/2018-03-07-01-33-33.bpo-33016.Z_Med0.rst
0 → 100644
View file @
3b20d345
Fix potential use of uninitialized memory in nt._getfinalpathname
Modules/posixmodule.c
View file @
3b20d345
...
...
@@ -303,12 +303,6 @@ extern int lstat(const char *, struct stat *);
#ifdef HAVE_PROCESS_H
#include <process.h>
#endif
#ifndef VOLUME_NAME_DOS
#define VOLUME_NAME_DOS 0x0
#endif
#ifndef VOLUME_NAME_NT
#define VOLUME_NAME_NT 0x2
#endif
#ifndef IO_REPARSE_TAG_SYMLINK
#define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
#endif
...
...
@@ -3731,11 +3725,10 @@ os__getfinalpathname_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=621a3c79bc29ebfa input=2b6b6c7cbad5fb84]*/
{
HANDLE
hFile
;
int
buf_size
;
wchar_t
*
target_path
;
wchar_t
buf
[
MAXPATHLEN
],
*
target_path
=
buf
;
int
buf_size
=
Py_ARRAY_LENGTH
(
buf
)
;
int
result_length
;
PyObject
*
result
;
const
char
*
err
=
NULL
;
Py_BEGIN_ALLOW_THREADS
hFile
=
CreateFileW
(
...
...
@@ -3747,55 +3740,52 @@ os__getfinalpathname_impl(PyObject *module, path_t *path)
/* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
FILE_FLAG_BACKUP_SEMANTICS
,
NULL
);
Py_END_ALLOW_THREADS
if
(
hFile
==
INVALID_HANDLE_VALUE
)
{
err
=
"CreateFileW"
;
goto
done1
;
return
win32_error_object
(
"CreateFileW"
,
path
->
object
);
}
/* We have a good handle to the target, use it to determine the
target path name. */
buf_size
=
GetFinalPathNameByHandleW
(
hFile
,
0
,
0
,
VOLUME_NAME_NT
);
if
(
!
buf_size
)
{
err
=
"GetFinalPathNameByHandle"
;
goto
done1
;
}
done1:
Py_END_ALLOW_THREADS
if
(
err
)
return
win32_error_object
(
err
,
path
->
object
);
target_path
=
PyMem_New
(
wchar_t
,
buf_size
+
1
);
if
(
!
target_path
)
return
PyErr_NoMemory
();
while
(
1
)
{
Py_BEGIN_ALLOW_THREADS
result_length
=
GetFinalPathNameByHandleW
(
hFile
,
target_path
,
buf_size
,
VOLUME_NAME_DOS
);
Py_END_ALLOW_THREADS
if
(
!
result_length
)
{
err
=
"GetFinalPathNameByHandle"
;
goto
done2
;
result
=
win32_error_object
(
"GetFinalPathNameByHandleW"
,
path
->
object
);
goto
cleanup
;
}
if
(
!
CloseHandle
(
hFile
))
{
err
=
"CloseHandle"
;
goto
done2
;
if
(
result_length
<
buf_size
)
{
break
;
}
done2:
Py_END_ALLOW_THREADS
if
(
err
)
{
PyMem_Free
(
target_path
);
return
win32_error_object
(
err
,
path
->
object
);
wchar_t
*
tmp
;
tmp
=
PyMem_Realloc
(
target_path
!=
buf
?
target_path
:
NULL
,
result_length
*
sizeof
(
*
tmp
));
if
(
!
tmp
)
{
result
=
PyErr_NoMemory
();
goto
cleanup
;
}
buf_size
=
result_length
;
target_path
=
tmp
;
}
target_path
[
result_length
]
=
0
;
result
=
PyUnicode_FromWideChar
(
target_path
,
result_length
);
PyMem_Free
(
target_path
);
if
(
path
->
narrow
)
Py_SETREF
(
result
,
PyUnicode_EncodeFSDefault
(
result
));
return
result
;
cleanup:
if
(
target_path
!=
buf
)
{
PyMem_Free
(
target_path
);
}
CloseHandle
(
hFile
);
return
result
;
}
/*[clinic input]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment