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
42bf8fc9
Commit
42bf8fc9
authored
Dec 30, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25961: Disallowed null characters in the type name.
Simplified testing for null characters in __name__ setter.
parent
beb652cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
28 deletions
+19
-28
Misc/NEWS
Misc/NEWS
+2
-0
Objects/typeobject.c
Objects/typeobject.c
+17
-28
No files found.
Misc/NEWS
View file @
42bf8fc9
...
@@ -10,6 +10,8 @@ Release date: tba
...
@@ -10,6 +10,8 @@ Release date: tba
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #25961: Disallowed null characters in the type name.
- Issue #25973: Fix segfault when an invalid nonlocal statement binds a name
- Issue #25973: Fix segfault when an invalid nonlocal statement binds a name
starting with two underscores.
starting with two underscores.
...
...
Objects/typeobject.c
View file @
42bf8fc9
...
@@ -401,9 +401,8 @@ type_qualname(PyTypeObject *type, void *context)
...
@@ -401,9 +401,8 @@ type_qualname(PyTypeObject *type, void *context)
static
int
static
int
type_set_name
(
PyTypeObject
*
type
,
PyObject
*
value
,
void
*
context
)
type_set_name
(
PyTypeObject
*
type
,
PyObject
*
value
,
void
*
context
)
{
{
PyHeapTypeObject
*
et
;
const
char
*
tp_name
;
char
*
tp_name
;
Py_ssize_t
name_size
;
PyObject
*
tmp
;
if
(
!
check_set_special_type_attr
(
type
,
value
,
"__name__"
))
if
(
!
check_set_special_type_attr
(
type
,
value
,
"__name__"
))
return
-
1
;
return
-
1
;
...
@@ -414,33 +413,18 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
...
@@ -414,33 +413,18 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
return
-
1
;
return
-
1
;
}
}
/* Check absence of null characters */
tp_name
=
PyUnicode_AsUTF8AndSize
(
value
,
&
name_size
);
tmp
=
PyUnicode_FromStringAndSize
(
"
\0
"
,
1
);
if
(
tp_name
==
NULL
)
if
(
tmp
==
NULL
)
return
-
1
;
return
-
1
;
if
(
PyUnicode_Contains
(
value
,
tmp
)
!=
0
)
{
if
(
strlen
(
tp_name
)
!=
(
size_t
)
name_size
)
{
Py_DECREF
(
tmp
);
PyErr_SetString
(
PyExc_ValueError
,
PyErr_Format
(
PyExc_ValueError
,
"type name must not contain null characters"
);
"__name__ must not contain null bytes"
);
return
-
1
;
return
-
1
;
}
}
Py_DECREF
(
tmp
);
tp_name
=
_PyUnicode_AsString
(
value
);
if
(
tp_name
==
NULL
)
return
-
1
;
et
=
(
PyHeapTypeObject
*
)
type
;
Py_INCREF
(
value
);
/* Wait until et is a sane state before Py_DECREF'ing the old et->ht_name
value. (Bug #16447.) */
tmp
=
et
->
ht_name
;
et
->
ht_name
=
value
;
type
->
tp_name
=
tp_name
;
type
->
tp_name
=
tp_name
;
Py_DECREF
(
tmp
);
Py_INCREF
(
value
);
Py_SETREF
(((
PyHeapTypeObject
*
)
type
)
->
ht_name
,
value
);
return
0
;
return
0
;
}
}
...
@@ -2285,8 +2269,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
...
@@ -2285,8 +2269,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
PyTypeObject
*
type
=
NULL
,
*
base
,
*
tmptype
,
*
winner
;
PyTypeObject
*
type
=
NULL
,
*
base
,
*
tmptype
,
*
winner
;
PyHeapTypeObject
*
et
;
PyHeapTypeObject
*
et
;
PyMemberDef
*
mp
;
PyMemberDef
*
mp
;
Py_ssize_t
i
,
nbases
,
nslots
,
slotoffset
,
add_dict
,
add_weak
;
Py_ssize_t
i
,
nbases
,
nslots
,
slotoffset
,
name_size
;
int
j
,
may_add_dict
,
may_add_weak
;
int
j
,
may_add_dict
,
may_add_weak
,
add_dict
,
add_weak
;
_Py_IDENTIFIER
(
__qualname__
);
_Py_IDENTIFIER
(
__qualname__
);
_Py_IDENTIFIER
(
__slots__
);
_Py_IDENTIFIER
(
__slots__
);
...
@@ -2509,9 +2493,14 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
...
@@ -2509,9 +2493,14 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
type
->
tp_as_sequence
=
&
et
->
as_sequence
;
type
->
tp_as_sequence
=
&
et
->
as_sequence
;
type
->
tp_as_mapping
=
&
et
->
as_mapping
;
type
->
tp_as_mapping
=
&
et
->
as_mapping
;
type
->
tp_as_buffer
=
&
et
->
as_buffer
;
type
->
tp_as_buffer
=
&
et
->
as_buffer
;
type
->
tp_name
=
_PyUnicode_AsString
(
nam
e
);
type
->
tp_name
=
PyUnicode_AsUTF8AndSize
(
name
,
&
name_siz
e
);
if
(
!
type
->
tp_name
)
if
(
!
type
->
tp_name
)
goto
error
;
goto
error
;
if
(
strlen
(
type
->
tp_name
)
!=
(
size_t
)
name_size
)
{
PyErr_SetString
(
PyExc_ValueError
,
"type name must not contain null characters"
);
goto
error
;
}
/* Set tp_base and tp_bases */
/* Set tp_base and tp_bases */
type
->
tp_bases
=
bases
;
type
->
tp_bases
=
bases
;
...
...
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