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

Trying To Concatenate Bytes and String in SMTPLIB #87291

Closed
boom0192 mannequin opened this issue Feb 4, 2021 · 5 comments
Closed

Trying To Concatenate Bytes and String in SMTPLIB #87291

boom0192 mannequin opened this issue Feb 4, 2021 · 5 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@boom0192
Copy link
Mannequin

boom0192 mannequin commented Feb 4, 2021

BPO 43125
Nosy @gst, @corona10
PRs
  • bpo-43125: Fix: return expected type (str), not original value (bytes) in email/base64mime.py::body_encode #24476
  • 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 2021-03-30.08:38:10.825>
    created_at = <Date 2021-02-04.13:23:28.718>
    labels = ['interpreter-core', 'type-bug', '3.10']
    title = 'Trying To Concatenate Bytes and String in SMTPLIB'
    updated_at = <Date 2021-03-30.08:38:10.824>
    user = 'https://bugs.python.org/boom0192'

    bugs.python.org fields:

    activity = <Date 2021-03-30.08:38:10.824>
    actor = 'corona10'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-30.08:38:10.825>
    closer = 'corona10'
    components = ['Interpreter Core']
    creation = <Date 2021-02-04.13:23:28.718>
    creator = 'boom0192'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43125
    keywords = ['patch']
    message_count = 5.0
    messages = ['386482', '386594', '386597', '386604', '389806']
    nosy_count = 3.0
    nosy_names = ['gstarck', 'corona10', 'boom0192']
    pr_nums = ['24476']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43125'
    versions = ['Python 3.10']

    @boom0192
    Copy link
    Mannequin Author

    boom0192 mannequin commented Feb 4, 2021

    The space is string, and either mechanism and/or response are bytes.
    smtplib.py:634
    response = encode_base64(initial_response.encode('ascii'), eol='')
    (code, resp) = self.docmd("AUTH", mechanism + " " + response)

    import smtplib, ssl
    port = 587  
    smtp_server = "---------------"
    smtpserver = smtplib.SMTP(smtp_server, port)
    smtpserver.set_debuglevel(2)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login("", "")

    12:40:37.614737 send: 'ehlo [10.60.69.196]\r\n'
    12:40:37.665528 reply: b'250-MWHPR20CA0007.outlook.office365.com Hello [65.54.12.68]\r\n'
    12:40:37.665666 reply: b'250-SIZE 157286400\r\n'
    12:40:37.665761 reply: b'250-PIPELINING\r\n'
    12:40:37.665788 reply: b'250-DSN\r\n'
    12:40:37.665806 reply: b'250-ENHANCEDSTATUSCODES\r\n'
    12:40:37.665825 reply: b'250-STARTTLS\r\n'
    12:40:37.665842 reply: b'250-8BITMIME\r\n'
    12:40:37.665859 reply: b'250-BINARYMIME\r\n'
    12:40:37.665876 reply: b'250-CHUNKING\r\n'
    12:40:37.665893 reply: b'250 SMTPUTF8\r\n'
    12:40:37.665919 reply: retcode (250); Msg: b'MWHPR20CA0007.outlook.office365.com Hello [65.54.12.68]\nSIZE 157286400\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\nSTARTTLS\n8BITMIME\nBINARYMIME\nCHUNKING\nSMTPUTF8'
    12:40:37.666440 send: 'STARTTLS\r\n'
    12:40:37.716214 reply: b'220 2.0.0 SMTP server ready\r\n'
    12:40:37.716265 reply: retcode (220); Msg: b'2.0.0 SMTP server ready'
    12:40:37.878320 send: 'ehlo [10.60.69.196]\r\n'
    12:40:37.928198 reply: b'250-MWHPR20CA0007.outlook.office365.com Hello [65.54.12.68]\r\n'
    12:40:37.928259 reply: b'250-SIZE 157286400\r\n'
    12:40:37.928285 reply: b'250-PIPELINING\r\n'
    12:40:37.928304 reply: b'250-DSN\r\n'
    12:40:37.928323 reply: b'250-ENHANCEDSTATUSCODES\r\n'
    12:40:37.928437 reply: b'250-AUTH LOGIN XOAUTH2\r\n'
    12:40:37.928461 reply: b'250-8BITMIME\r\n'
    12:40:37.928494 reply: b'250-BINARYMIME\r\n'
    12:40:37.928511 reply: b'250-CHUNKING\r\n'
    12:40:37.928528 reply: b'250 SMTPUTF8\r\n'
    12:40:37.928552 reply: retcode (250); Msg: b'MWHPR20CA0007.outlook.office365.com Hello [65.54.12.68]\nSIZE 157286400\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\nAUTH LOGIN XOAUTH2\n8BITMIME\nBINARYMIME\nCHUNKING\nSMTPUTF8'
    Traceback (most recent call last):
      File "mail9.py", line 18, in <module>
        smtpserver.login("", "")
      File "/aae/msio_install_release1.9/scoring_engine.20201201.3.8.3/lib/python3.8/smtplib.py", line 723, in login
        (code, resp) = self.auth(
      File "/aae/msio_install_release1.9/scoring_engine.20201201.3.8.3/lib/python3.8/smtplib.py", line 635, in auth
        (code, resp) = self.docmd("AUTH", mechanism + " " + response)
    TypeError: can only concatenate str (not "bytes") to str

    @boom0192 boom0192 mannequin added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 4, 2021
    @gst
    Copy link
    Mannequin

    gst mannequin commented Feb 7, 2021

    I reproduced directly. by using a valid smtp server.

    @gst
    Copy link
    Mannequin

    gst mannequin commented Feb 7, 2021

    problem seems to/could be in /usr/lib/python3.8/email/base64mime.py

    def body_encode(s, maxlinelen=76, eol=NL):
        r"""Encode a string with base64.
    
        Each line will be wrapped at, at most, maxlinelen characters (defaults to
        76 characters).
    
        Each line of encoded text will end with eol, which defaults to "\n".  Set
        this to "\r\n" if you will be using the result of this function directly
        in an email.
        """
        if not s:
            return s
    

    If function is supposed to return str for any bytes input, then there it is returning the original bytes instance.. which is the trouble. it should return "" and that's it ?

    I would like to work/contribute on this issue.. I'll further investigate this issue and possible solution and comes with a patch rather sooner than later..

    @gst
    Copy link
    Mannequin

    gst mannequin commented Feb 7, 2021

    I filled the PR #24476

    feel free to comment.

    @corona10
    Copy link
    Member

    New changeset cf35e05 by Grégory Starck in branch 'master':
    bpo-43125: Fix: return expected type (str), not original value (bytes) in email/base64mime.py::body_encode (GH-24476)
    cf35e05

    @corona10 corona10 added 3.10 only security fixes and removed 3.8 only security fixes labels Mar 30, 2021
    @corona10 corona10 added 3.10 only security fixes and removed 3.8 only security fixes labels Mar 30, 2021
    @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
    3.10 only security fixes 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