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

imaplib authenticate raises TypeError if authenticator tries to abort #67967

Closed
craigh mannequin opened this issue Mar 25, 2015 · 8 comments
Closed

imaplib authenticate raises TypeError if authenticator tries to abort #67967

craigh mannequin opened this issue Mar 25, 2015 · 8 comments
Labels
stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@craigh
Copy link
Mannequin

craigh mannequin commented Mar 25, 2015

BPO 23779
Nosy @warsaw, @ericvsmith, @rbtcollins, @bitdancer, @berkerpeksag
Files
  • imap_auth.patch: imaplib.py patch
  • imap_auth2.patch
  • imap_auth3.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 = None
    closed_at = <Date 2015-07-30.21:04:24.572>
    created_at = <Date 2015-03-25.22:21:23.664>
    labels = ['type-bug', 'library', 'expert-email']
    title = 'imaplib authenticate raises TypeError if authenticator tries to abort'
    updated_at = <Date 2015-07-30.21:04:24.570>
    user = 'https://bugs.python.org/craigh'

    bugs.python.org fields:

    activity = <Date 2015-07-30.21:04:24.570>
    actor = 'rbcollins'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-07-30.21:04:24.572>
    closer = 'rbcollins'
    components = ['Library (Lib)', 'email']
    creation = <Date 2015-03-25.22:21:23.664>
    creator = 'craigh'
    dependencies = []
    files = ['38694', '38749', '38768']
    hgrepos = []
    issue_num = 23779
    keywords = ['patch']
    message_count = 8.0
    messages = ['239283', '239656', '239658', '239701', '239752', '239803', '247698', '247699']
    nosy_count = 7.0
    nosy_names = ['barry', 'eric.smith', 'rbcollins', 'craigh', 'r.david.murray', 'python-dev', 'berker.peksag']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23779'
    versions = ['Python 3.4', 'Python 3.5']

    @craigh
    Copy link
    Mannequin Author

    craigh mannequin commented Mar 25, 2015

    If the authenticator object passed to the IMAP authenticate method tries to abort the handshake by returning None, TypeError is raised instead of sending the * line to the server.

    >>> import imaplib
    >>> imap = imaplib.IMAP4_SSL('imap.gmail.com')
    >>> imap.authenticate(b'PLAIN', lambda x: None)
    Traceback (most recent call last):
      File "<pyshell#5>", line 1, in <module>
        imap.authenticate(b'PLAIN', lambda x: None)
      File "C:\Python34\lib\imaplib.py", line 380, in authenticate
        typ, dat = self._simple_command('AUTHENTICATE', mech)
      File "C:\Python34\lib\imaplib.py", line 1133, in _simple_command
        return self._command_complete(name, self._command(name, *args))
      File "C:\Python34\lib\imaplib.py", line 940, in _command
        self.send(literal)
      File "C:\Python34\lib\imaplib.py", line 276, in send
        self.sock.sendall(data)
      File "C:\Python34\lib\ssl.py", line 723, in sendall
        v = self.send(data[count:])
      File "C:\Python34\lib\ssl.py", line 684, in send
        v = self._sslobj.write(data)
    TypeError: 'str' does not support the buffer interface

    The problem is that _Authenticator.process returns a string instead of bytes in this case.

    @craigh craigh mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 25, 2015
    @berkerpeksag
    Copy link
    Member

    Thanks for the report and the patch, Craig. Could you convert your reproducer to a test case? imaplib tests are located in Lib/test/test_imaplib.py.

    @craigh
    Copy link
    Mannequin Author

    craigh mannequin commented Mar 31, 2015

    New patch is attached.

    @bitdancer
    Copy link
    Member

    The patch looks good to me, except that I think it would be better if the test verified that the '*' response is received by the server (perhaps return OK if we don't get it?)

    @craigh
    Copy link
    Mannequin Author

    craigh mannequin commented Mar 31, 2015

    Okay, I attached another patch. The new version of the test returns success if the client's response is anything other than the abort line (*\r\n).

    It fails with the current version of imaplib, fails if I change _Authenticator.process to output a byte-string besides *, and succeeds with the change in the patch.

    @bitdancer
    Copy link
    Member

    Looks good to me, thanks.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 30, 2015

    New changeset fe55a36a335b by Robert Collins in branch '3.4':
    Issue bpo-23779: imaplib raises TypeError if authenticator tries to abort.
    https://hg.python.org/cpython/rev/fe55a36a335b

    New changeset b6f04b9d8c12 by Robert Collins in branch '3.5':
    Issue bpo-23779: imaplib raises TypeError if authenticator tries to abort.
    https://hg.python.org/cpython/rev/b6f04b9d8c12

    New changeset 0879f2c53289 by Robert Collins in branch 'default':
    Issue bpo-23779: imaplib raises TypeError if authenticator tries to abort.
    https://hg.python.org/cpython/rev/0879f2c53289

    @rbtcollins
    Copy link
    Member

    Thanks for the patch. Applied to 3.4 through 3.6.

    @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 topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants