New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow the null character in type name #70149
Comments
The null character is allowed in __name__ setter (but error message is a little confusing). >>> class A: pass
...
>>> A.__name__ = 'B\0'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: __name__ must not contain null bytes But is allowed in type constructor. >>> t = type('B\0C', (), {})
>>> t
<class '__main__.BC'>
>>> t.__name__
'B\x00C' |
Why are null bytes being excluded from type names in the first place? |
Because tp_name is a pointer to null-terminated C string and there is no way to distinguish the name containg the null byte from the name terminated by null byte. tp_name is used for example in error messages. >>> t = type('B\0C', (), {})
>>> t.__name__
'B\x00C'
>>> t() + 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'B' and 'int' |
New changeset 29cc6b2f9d28 by Serhiy Storchaka in branch '2.7': New changeset d2417971c934 by Serhiy Storchaka in branch '3.5': New changeset 1ab7bcd4e176 by Serhiy Storchaka in branch 'default': |
Hi all, I fixed a compile error introduced in Python 2.7 by this issue. There is a jump made to an nonexistent label "error" in type_new function in Objects/typeobject.c. Please see the attached patch. Regards, |
Thank you Florin. How could I miss this? But your patch is not correct. It leads to double free and deallocating using non-initialized pointer. It also contains trailing spaces and incorrect indentation. |
New changeset 57fea6f75ac2 by Serhiy Storchaka in branch '2.7': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: