Skip to content
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

Closed
serhiy-storchaka opened this issue Dec 27, 2015 · 7 comments
Closed

Disallow the null character in type name #70149

serhiy-storchaka opened this issue Dec 27, 2015 · 7 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 25961
Nosy @serhiy-storchaka, @pppery, @florinpapa
Files
  • type_name_null.patch
  • type_name_null_fix.patch
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-12-30.19:43:35.822>
    created_at = <Date 2015-12-27.14:28:00.837>
    labels = ['interpreter-core', 'type-bug']
    title = 'Disallow the null character in type name'
    updated_at = <Date 2015-12-31.10:08:15.852>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-12-31.10:08:15.852>
    actor = 'python-dev'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-12-30.19:43:35.822>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2015-12-27.14:28:00.837>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['41434', '41460']
    hgrepos = []
    issue_num = 25961
    keywords = ['patch']
    message_count = 7.0
    messages = ['257076', '257189', '257191', '257236', '257250', '257251', '257252']
    nosy_count = 4.0
    nosy_names = ['python-dev', 'serhiy.storchaka', 'ppperry', 'florin.papa']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25961'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @serhiy-storchaka
    Copy link
    Member Author

    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'

    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Dec 27, 2015
    @pppery
    Copy link
    Mannequin

    pppery mannequin commented Dec 29, 2015

    Why are null bytes being excluded from type names in the first place?

    @serhiy-storchaka
    Copy link
    Member Author

    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'

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 30, 2015

    New changeset 29cc6b2f9d28 by Serhiy Storchaka in branch '2.7':
    Issue bpo-25961: Disallowed null characters in the type name.
    https://hg.python.org/cpython/rev/29cc6b2f9d28

    New changeset d2417971c934 by Serhiy Storchaka in branch '3.5':
    Issue bpo-25961: Disallowed null characters in the type name.
    https://hg.python.org/cpython/rev/d2417971c934

    New changeset 1ab7bcd4e176 by Serhiy Storchaka in branch 'default':
    Issue bpo-25961: Disallowed null characters in the type name.
    https://hg.python.org/cpython/rev/1ab7bcd4e176

    @florinpapa
    Copy link
    Mannequin

    florinpapa mannequin commented Dec 31, 2015

    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,
    Florin Papa

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 31, 2015

    New changeset 57fea6f75ac2 by Serhiy Storchaka in branch '2.7':
    Issue bpo-25961: Fixed compilation error and a leak in type constructor.
    https://hg.python.org/cpython/rev/57fea6f75ac2

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant