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
1efb33a6
Commit
1efb33a6
authored
Oct 03, 2011
by
Meador Inge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12881: ctypes: Fix segfault with large structure field names.
parent
5d0de3fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
Lib/ctypes/test/test_structures.py
Lib/ctypes/test/test_structures.py
+12
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_ctypes/stgdict.c
Modules/_ctypes/stgdict.c
+7
-1
No files found.
Lib/ctypes/test/test_structures.py
View file @
1efb33a6
...
...
@@ -326,6 +326,18 @@ class StructureTestCase(unittest.TestCase):
else
:
self
.
assertEqual
(
msg
,
"(Phone) TypeError: too many initializers"
)
def
test_huge_field_name
(
self
):
# issue12881: segfault with large structure field names
def
create_class
(
length
):
class
S
(
Structure
):
_fields_
=
[(
'x'
*
length
,
c_int
)]
for
length
in
[
10
**
i
for
i
in
range
(
0
,
8
)]:
try
:
create_class
(
length
)
except
MemoryError
:
# MemoryErrors are OK, we just don't want to segfault
pass
def
get_except
(
self
,
func
,
*
args
):
try
:
...
...
Misc/NEWS
View file @
1efb33a6
...
...
@@ -87,6 +87,8 @@ Tests
Extension Modules
-----------------
- Issue #12881: ctypes: Fix segfault with large structure field names.
- Issue #13058: ossaudiodev: fix a file descriptor leak on error. Patch by
Thomas Jarosch.
...
...
Modules/_ctypes/stgdict.c
View file @
1efb33a6
...
...
@@ -496,13 +496,19 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
}
len
=
strlen
(
fieldname
)
+
strlen
(
fieldfmt
);
buf
=
alloca
(
len
+
2
+
1
);
buf
=
PyMem_Malloc
(
len
+
2
+
1
);
if
(
buf
==
NULL
)
{
Py_DECREF
(
pair
);
PyErr_NoMemory
();
return
-
1
;
}
sprintf
(
buf
,
"%s:%s:"
,
fieldfmt
,
fieldname
);
ptr
=
stgdict
->
format
;
stgdict
->
format
=
_ctypes_alloc_format_string
(
stgdict
->
format
,
buf
);
PyMem_Free
(
ptr
);
PyMem_Free
(
buf
);
if
(
stgdict
->
format
==
NULL
)
{
Py_DECREF
(
pair
);
...
...
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