Skip to content

telnetlib module broken by str to unicode conversion #47975

Closed

Description

@hdima
mannequin
BPO 3725
Nosy @amauryfa, @vstinner, @benjaminp
Files
  • telnet_bytes.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/benjaminp'
    closed_at = <Date 2008-10-15.20:54:40.089>
    created_at = <Date 2008-08-29.12:43:46.004>
    labels = ['library', 'type-crash', 'release-blocker']
    title = 'telnetlib module broken by str to unicode conversion'
    updated_at = <Date 2008-10-15.20:54:40.087>
    user = 'https://bugs.python.org/hdima'

    bugs.python.org fields:

    activity = <Date 2008-10-15.20:54:40.087>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-10-15.20:54:40.089>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2008-08-29.12:43:46.004>
    creator = 'hdima'
    dependencies = []
    files = ['11788']
    hgrepos = []
    issue_num = 3725
    keywords = ['patch']
    message_count = 7.0
    messages = ['72131', '72132', '74735', '74770', '74780', '74794', '74815']
    nosy_count = 4.0
    nosy_names = ['hdima', 'amaury.forgeotdarc', 'vstinner', 'benjamin.peterson']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue3725'
    versions = ['Python 3.0']

    Activity

    1. hdima commented on Aug 29, 2008

      hdimamannequin
      MannequinAuthor

      Simple example:

      >>> from telnetlib import Telnet
      >>> t = Telnet("google.com", 80)
      >>> t.write("GET / HTTP/1.1\r\n")        
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/py3k/Lib/telnetlib.py", line 280, in write
          self.sock.sendall(buffer)
      TypeError: sendall() argument 1 must be string or buffer, not str
      >>> t.write(b"GET / HTTP/1.1\r\n")
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/py3k/Lib/telnetlib.py", line 277, in write
          if IAC in buffer:
      TypeError: Type str doesn't support the buffer API
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Aug 29, 2008
    3. hdima commented on Aug 29, 2008

      hdimamannequin
      MannequinAuthor

      I think only bytes need to be allowed for write() and read*() because of
      low-level nature of Telnet. I can create a patch later.

    4. vstinner commented on Oct 14, 2008

      @vstinner
      Member

      I think that telnet should only use bytes (and not characters). For an
      HTTP connection, the charset is only known after parsing the HTTP
      headers. So telnet should use bytes, and your HTTP browser will
      convert bytes to characters using the charset from the HTTP headers.
      My patch only uses bytes for internal buffering and special codes
      (IAC, DONT, ENCRYPT, etc.).

      Example to test the library (Starwars, telnet, ISO-8859-1):
      from telnetlib import Telnet
      from sys import stdout
      ipv4 = "towel.blinkenlights.nl"
      ipv6 = "2001:980:ffe:1::42"
      t = Telnet(ipv6, 23)
      while True:
      command = t.read_some()
      command = str(command, "ISO-8859-1")
      stdout.write(command)

      Example to test the library (Google, HTTP, ASCII):
      from telnetlib import Telnet
      t = Telnet("www.google.com", 80)
      t.write(b'GET / HTTP/1.0\r\n\r\n')
      answer = t.read_all()
      answer = str(answer, "ASCII")
      print(answer)

    5. benjaminp commented on Oct 14, 2008

      @benjaminp
      Contributor

      The patch looks pretty straightforward to me. If somebody else gives
      their nod, I'll apply it.

    6. self-assigned this
      on Oct 14, 2008
    7. amauryfa commented on Oct 14, 2008

      @amauryfa
      Contributor

      Yes, the patch is good.

      I think that documentation (both Doc\library\telnetlib.rst and the
      docstrings in telnetlib.py) should reflect the change, at least the code
      samples.

    8. hdima commented on Oct 15, 2008

      hdimamannequin
      MannequinAuthor

      The patch is good. It's exactly what I told about in msg72132.

    9. benjaminp commented on Oct 15, 2008

      @benjaminp
      Contributor

      Fixed in r66904.

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    release-blockerstdlibStandard Library Python modules in the Lib/ directorytype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions