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

socket.sendto raises incorrect exception when passed incorrect types #54378

Closed
exarkun mannequin opened this issue Oct 21, 2010 · 5 comments
Closed

socket.sendto raises incorrect exception when passed incorrect types #54378

exarkun mannequin opened this issue Oct 21, 2010 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@exarkun
Copy link
Mannequin

exarkun mannequin commented Oct 21, 2010

BPO 10169
Nosy @pitrou, @giampaolo, @ezio-melotti
Files
  • issue10169.diff: Patch against 2.7.
  • issue10169-2.diff: Patch against 2.7 w/ tests.
  • 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/ezio-melotti'
    closed_at = <Date 2011-05-07.16:54:44.008>
    created_at = <Date 2010-10-21.17:22:06.335>
    labels = ['type-bug', 'library']
    title = 'socket.sendto raises incorrect exception when passed incorrect types'
    updated_at = <Date 2011-05-07.16:54:44.006>
    user = 'https://bugs.python.org/exarkun'

    bugs.python.org fields:

    activity = <Date 2011-05-07.16:54:44.006>
    actor = 'ezio.melotti'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2011-05-07.16:54:44.008>
    closer = 'ezio.melotti'
    components = ['Library (Lib)']
    creation = <Date 2010-10-21.17:22:06.335>
    creator = 'exarkun'
    dependencies = []
    files = ['21867', '21868']
    hgrepos = []
    issue_num = 10169
    keywords = ['patch', 'needs review']
    message_count = 5.0
    messages = ['119320', '135020', '135022', '135477', '135481']
    nosy_count = 6.0
    nosy_names = ['exarkun', 'pitrou', 'falsetru', 'giampaolo.rodola', 'ezio.melotti', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10169'
    versions = ['Python 2.7']

    @exarkun
    Copy link
    Mannequin Author

    exarkun mannequin commented Oct 21, 2010

    >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    >>> s.bind(('', 0))
    >>> s.sendto(u'hellé', s.getsockname())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: sendto() takes exactly 3 arguments (2 given)
    >>> s.sendto(3, s.getsockname())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: sendto() takes exactly 3 arguments (2 given)
    >>> s.sendto('hello', s.getsockname())
    5

    The TypeError gives the wrong explanation for what's wrong.

    @exarkun exarkun mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 21, 2010
    @ezio-melotti
    Copy link
    Member

    The original code was trying to call PyArg_ParseTuple assuming 2 args and in case of failure (any failure) was starting over assuming 3 args.
    The attached patch makes PyArg_ParseTuple accept 2 or 3 args and re-arranges the last two if 'flags' is passed.
    The tests pass, but a few more tests should be added.

    @ezio-melotti ezio-melotti self-assigned this May 3, 2011
    @ezio-melotti
    Copy link
    Member

    Added tests and fixed all the problems they found.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 7, 2011

    New changeset 7c3a20b5943a by Ezio Melotti in branch '2.7':
    bpo-10169: Fix argument parsing in socket.sendto() to avoid error masking.
    http://hg.python.org/cpython/rev/7c3a20b5943a

    @ezio-melotti
    Copy link
    Member

    This turned out to be a duplicate of bpo-5421 already fixed in 3.x, so I backported the patch and added the tests to 3.x too.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant