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
8eca47ea
Commit
8eca47ea
authored
Jan 04, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some overflow checks before multiplying (closes #23165)
parent
44d315ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
Misc/NEWS
Misc/NEWS
+3
-0
Python/fileutils.c
Python/fileutils.c
+13
-3
No files found.
Misc/NEWS
View file @
8eca47ea
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.6?
Core and Builtins
-----------------
- Issue #23165: Perform overflow checks before allocating memory in the
_Py_char2wchar function.
- Issue #19529: Fix a potential crash in converting Unicode objects to wchar_t
when Py_UNICODE is 4 bytes but wchar_t is 2 bytes, for example on AIX.
...
...
Python/fileutils.c
View file @
8eca47ea
...
...
@@ -169,8 +169,11 @@ decode_ascii_surrogateescape(const char *arg, size_t *size)
wchar_t
*
res
;
unsigned
char
*
in
;
wchar_t
*
out
;
size_t
argsize
=
strlen
(
arg
)
+
1
;
res
=
PyMem_Malloc
((
strlen
(
arg
)
+
1
)
*
sizeof
(
wchar_t
));
if
(
argsize
>
PY_SSIZE_T_MAX
/
sizeof
(
wchar_t
))
return
NULL
;
res
=
PyMem_Malloc
(
argsize
*
sizeof
(
wchar_t
));
if
(
!
res
)
return
NULL
;
...
...
@@ -250,10 +253,15 @@ _Py_char2wchar(const char* arg, size_t *size)
argsize
=
mbstowcs
(
NULL
,
arg
,
0
);
#endif
if
(
argsize
!=
(
size_t
)
-
1
)
{
res
=
(
wchar_t
*
)
PyMem_Malloc
((
argsize
+
1
)
*
sizeof
(
wchar_t
));
if
(
argsize
==
PY_SSIZE_T_MAX
)
goto
oom
;
argsize
+=
1
;
if
(
argsize
>
PY_SSIZE_T_MAX
/
sizeof
(
wchar_t
))
goto
oom
;
res
=
(
wchar_t
*
)
PyMem_Malloc
(
argsize
*
sizeof
(
wchar_t
));
if
(
!
res
)
goto
oom
;
count
=
mbstowcs
(
res
,
arg
,
argsize
+
1
);
count
=
mbstowcs
(
res
,
arg
,
argsize
);
if
(
count
!=
(
size_t
)
-
1
)
{
wchar_t
*
tmp
;
/* Only use the result if it contains no
...
...
@@ -276,6 +284,8 @@ _Py_char2wchar(const char* arg, size_t *size)
/* Overallocate; as multi-byte characters are in the argument, the
actual output could use less memory. */
argsize
=
strlen
(
arg
)
+
1
;
if
(
argsize
>
PY_SSIZE_T_MAX
/
sizeof
(
wchar_t
))
goto
oom
;
res
=
(
wchar_t
*
)
PyMem_Malloc
(
argsize
*
sizeof
(
wchar_t
));
if
(
!
res
)
goto
oom
;
...
...
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