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
4c98008a
Commit
4c98008a
authored
Feb 16, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
overflows. Added few missed PyErr_NoMemory().
parent
8427dec2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
15 deletions
+25
-15
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+6
-3
Modules/_ctypes/stgdict.c
Modules/_ctypes/stgdict.c
+8
-4
Modules/_localemodule.c
Modules/_localemodule.c
+2
-2
Modules/_ssl.c
Modules/_ssl.c
+4
-3
Python/peephole.c
Python/peephole.c
+5
-3
No files found.
Modules/_ctypes/_ctypes.c
View file @
4c98008a
...
...
@@ -4469,8 +4469,11 @@ Array_subscript(PyObject *_self, PyObject *item)
slicelen
);
}
dest
=
(
wchar_t
*
)
PyMem_Malloc
(
slicelen
*
sizeof
(
wchar_t
));
dest
=
PyMem_New
(
wchar_t
,
slicelen
);
if
(
dest
==
NULL
)
{
PyErr_NoMemory
();
return
NULL
;
}
for
(
cur
=
start
,
i
=
0
;
i
<
slicelen
;
cur
+=
step
,
i
++
)
{
...
...
@@ -5250,7 +5253,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
return
PyUnicode_FromWideChar
(
ptr
+
start
,
len
);
}
dest
=
(
wchar_t
*
)
PyMem_Malloc
(
len
*
sizeof
(
wchar_t
)
);
dest
=
PyMem_New
(
wchar_t
,
len
);
if
(
dest
==
NULL
)
return
PyErr_NoMemory
();
for
(
cur
=
start
,
i
=
0
;
i
<
len
;
cur
+=
step
,
i
++
)
{
...
...
Modules/_ctypes/stgdict.c
View file @
4c98008a
...
...
@@ -80,14 +80,18 @@ PyCStgDict_clone(StgDictObject *dst, StgDictObject *src)
if
(
src
->
format
)
{
dst
->
format
=
PyMem_Malloc
(
strlen
(
src
->
format
)
+
1
);
if
(
dst
->
format
==
NULL
)
if
(
dst
->
format
==
NULL
)
{
PyErr_NoMemory
();
return
-
1
;
}
strcpy
(
dst
->
format
,
src
->
format
);
}
if
(
src
->
shape
)
{
dst
->
shape
=
PyMem_Malloc
(
sizeof
(
Py_ssize_t
)
*
src
->
ndim
);
if
(
dst
->
shape
==
NULL
)
if
(
dst
->
shape
==
NULL
)
{
PyErr_NoMemory
();
return
-
1
;
}
memcpy
(
dst
->
shape
,
src
->
shape
,
sizeof
(
Py_ssize_t
)
*
src
->
ndim
);
}
...
...
@@ -388,7 +392,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
union_size
=
0
;
total_align
=
align
?
align
:
1
;
stgdict
->
ffi_type_pointer
.
type
=
FFI_TYPE_STRUCT
;
stgdict
->
ffi_type_pointer
.
elements
=
PyMem_
Malloc
(
sizeof
(
ffi_type
*
)
*
(
basedict
->
length
+
len
+
1
)
);
stgdict
->
ffi_type_pointer
.
elements
=
PyMem_
New
(
ffi_type
*
,
basedict
->
length
+
len
+
1
);
if
(
stgdict
->
ffi_type_pointer
.
elements
==
NULL
)
{
PyErr_NoMemory
();
return
-
1
;
...
...
@@ -406,7 +410,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
union_size
=
0
;
total_align
=
1
;
stgdict
->
ffi_type_pointer
.
type
=
FFI_TYPE_STRUCT
;
stgdict
->
ffi_type_pointer
.
elements
=
PyMem_
Malloc
(
sizeof
(
ffi_type
*
)
*
(
len
+
1
)
);
stgdict
->
ffi_type_pointer
.
elements
=
PyMem_
New
(
ffi_type
*
,
len
+
1
);
if
(
stgdict
->
ffi_type_pointer
.
elements
==
NULL
)
{
PyErr_NoMemory
();
return
-
1
;
...
...
Modules/_localemodule.c
View file @
4c98008a
...
...
@@ -314,7 +314,7 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
}
/* Convert the unicode strings to wchar[]. */
len1
=
PyUnicode_GET_SIZE
(
os1
)
+
1
;
ws1
=
PyMem_
MALLOC
(
len1
*
sizeof
(
wchar_t
)
);
ws1
=
PyMem_
NEW
(
wchar_t
,
len1
);
if
(
!
ws1
)
{
PyErr_NoMemory
();
goto
done
;
...
...
@@ -323,7 +323,7 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
goto
done
;
ws1
[
len1
-
1
]
=
0
;
len2
=
PyUnicode_GET_SIZE
(
os2
)
+
1
;
ws2
=
PyMem_
MALLOC
(
len2
*
sizeof
(
wchar_t
)
);
ws2
=
PyMem_
NEW
(
wchar_t
,
len2
);
if
(
!
ws2
)
{
PyErr_NoMemory
();
goto
done
;
...
...
Modules/_ssl.c
View file @
4c98008a
...
...
@@ -3891,10 +3891,11 @@ static int _setup_ssl_threads(void) {
if
(
_ssl_locks
==
NULL
)
{
_ssl_locks_count
=
CRYPTO_num_locks
();
_ssl_locks
=
(
PyThread_type_lock
*
)
PyMem_Malloc
(
sizeof
(
PyThread_type_lock
)
*
_ssl_locks_count
);
if
(
_ssl_locks
==
NULL
)
_ssl_locks
=
PyMem_New
(
PyThread_type_lock
,
_ssl_locks_count
);
if
(
_ssl_locks
==
NULL
)
{
PyErr_NoMemory
();
return
0
;
}
memset
(
_ssl_locks
,
0
,
sizeof
(
PyThread_type_lock
)
*
_ssl_locks_count
);
for
(
i
=
0
;
i
<
_ssl_locks_count
;
i
++
)
{
...
...
Python/peephole.c
View file @
4c98008a
...
...
@@ -242,7 +242,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
static
unsigned
int
*
markblocks
(
unsigned
char
*
code
,
Py_ssize_t
len
)
{
unsigned
int
*
blocks
=
(
unsigned
int
*
)
PyMem_Malloc
(
len
*
sizeof
(
int
)
);
unsigned
int
*
blocks
=
PyMem_New
(
unsigned
int
,
len
);
int
i
,
j
,
opcode
,
blockcnt
=
0
;
if
(
blocks
==
NULL
)
{
...
...
@@ -343,9 +343,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
goto
exitUnchanged
;
/* Mapping to new jump targets after NOPs are removed */
addrmap
=
(
int
*
)
PyMem_Malloc
(
codelen
*
sizeof
(
int
));
if
(
addrmap
==
NULL
)
addrmap
=
PyMem_New
(
int
,
codelen
);
if
(
addrmap
==
NULL
)
{
PyErr_NoMemory
();
goto
exitError
;
}
blocks
=
markblocks
(
codestr
,
codelen
);
if
(
blocks
==
NULL
)
...
...
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