[pypy-commit] pypy default: check for null bytes when setting __name__
bdkearns
noreply at buildbot.pypy.org
Fri May 2 03:36:42 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r71176:c7cd23b6b70f
Date: 2014-05-01 21:36 -0400
http://bitbucket.org/pypy/pypy/changeset/c7cd23b6b70f/
Log: check for null bytes when setting __name__
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -885,6 +885,12 @@
Abc.__name__ = 'Def'
assert Abc.__name__ == 'Def'
raises(TypeError, "Abc.__name__ = 42")
+ try:
+ Abc.__name__ = 'G\x00hi'
+ except ValueError as e:
+ assert str(e) == "__name__ must not contain null bytes"
+ else:
+ assert False
def test_compare(self):
class A(object):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -634,7 +634,10 @@
w_type = _check(space, w_type)
if not w_type.is_heaptype():
raise oefmt(space.w_TypeError, "can't set %N.__name__", w_type)
- w_type.name = space.str_w(w_value)
+ name = space.str_w(w_value)
+ if '\x00' in name:
+ raise oefmt(space.w_ValueError, "__name__ must not contain null bytes")
+ w_type.name = name
def descr_get__mro__(space, w_type):
w_type = _check(space, w_type)
More information about the pypy-commit
mailing list