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
55bf20ad
Commit
55bf20ad
authored
Oct 12, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#13096: Fix segfault in CTypes POINTER handling of large values.
Patch by Meador Inge.
parent
e73b8c64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
Lib/ctypes/test/test_pointers.py
Lib/ctypes/test/test_pointers.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_ctypes/callproc.c
Modules/_ctypes/callproc.c
+7
-2
No files found.
Lib/ctypes/test/test_pointers.py
View file @
55bf20ad
...
...
@@ -7,6 +7,8 @@ ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long
,
c_ulong
,
c_longlong
,
c_ulonglong
,
c_double
,
c_float
]
python_types
=
[
int
,
int
,
int
,
int
,
int
,
long
,
int
,
long
,
long
,
long
,
float
,
float
]
LargeNamedType
=
type
(
'T'
*
2
**
25
,
(
Structure
,),
{})
large_string
=
'T'
*
2
**
25
class
PointersTestCase
(
unittest
.
TestCase
):
...
...
@@ -188,5 +190,11 @@ class PointersTestCase(unittest.TestCase):
mth
=
WINFUNCTYPE
(
None
)(
42
,
"name"
,
(),
None
)
self
.
assertEqual
(
bool
(
mth
),
True
)
def
test_pointer_type_name
(
self
):
self
.
assertTrue
(
POINTER
(
LargeNamedType
))
def
test_pointer_type_str_name
(
self
):
self
.
assertTrue
(
POINTER
(
large_string
))
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
View file @
55bf20ad
...
...
@@ -37,6 +37,9 @@ Core and Builtins
Library
-------
-
Issue
#
13096
:
Fixed
segfault
in
CTypes
POINTER
handling
of
large
values
.
-
Issue
#
11694
:
Raise
ConversionError
in
xdrlib
as
documented
.
Patch
by
Filip
Gruszczy
ń
ski
and
Claudiu
Popa
.
...
...
Modules/_ctypes/callproc.c
View file @
55bf20ad
...
...
@@ -1807,7 +1807,9 @@ POINTER(PyObject *self, PyObject *cls)
return
result
;
}
if
(
PyString_CheckExact
(
cls
))
{
buf
=
alloca
(
strlen
(
PyString_AS_STRING
(
cls
))
+
3
+
1
);
buf
=
PyMem_Malloc
(
strlen
(
PyString_AS_STRING
(
cls
))
+
3
+
1
);
if
(
buf
==
NULL
)
return
PyErr_NoMemory
();
sprintf
(
buf
,
"LP_%s"
,
PyString_AS_STRING
(
cls
));
result
=
PyObject_CallFunction
((
PyObject
*
)
Py_TYPE
(
&
PyCPointer_Type
),
"s(O){}"
,
...
...
@@ -1818,13 +1820,16 @@ POINTER(PyObject *self, PyObject *cls)
key
=
PyLong_FromVoidPtr
(
result
);
}
else
if
(
PyType_Check
(
cls
))
{
typ
=
(
PyTypeObject
*
)
cls
;
buf
=
alloca
(
strlen
(
typ
->
tp_name
)
+
3
+
1
);
buf
=
PyMem_Malloc
(
strlen
(
typ
->
tp_name
)
+
3
+
1
);
if
(
buf
==
NULL
)
return
PyErr_NoMemory
();
sprintf
(
buf
,
"LP_%s"
,
typ
->
tp_name
);
result
=
PyObject_CallFunction
((
PyObject
*
)
Py_TYPE
(
&
PyCPointer_Type
),
"s(O){sO}"
,
buf
,
&
PyCPointer_Type
,
"_type_"
,
cls
);
PyMem_Free
(
buf
);
if
(
result
==
NULL
)
return
result
;
Py_INCREF
(
cls
);
...
...
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