diff options
-rw-r--r-- | paramiko/transport.py | 2 | ||||
-rw-r--r-- | paramiko/util.py | 9 | ||||
-rw-r--r-- | sites/www/changelog.rst | 4 | ||||
-rw-r--r-- | tests/test_util.py | 15 |
4 files changed, 23 insertions, 7 deletions
diff --git a/paramiko/transport.py b/paramiko/transport.py index 7a6c1d8d..eb488a18 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1979,7 +1979,7 @@ class Transport (threading.Thread): always_display = m.get_boolean() msg = m.get_string() lang = m.get_string() - self._log(DEBUG, 'Debug msg: ' + util.safe_string(msg)) + self._log(DEBUG, 'Debug msg: {0}'.format(util.safe_string(msg))) def _get_subsystem_handler(self, name): try: diff --git a/paramiko/util.py b/paramiko/util.py index f4ee3adc..ab1bb98d 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -115,12 +115,13 @@ def unhexify(s): def safe_string(s): - out = '' + out = b('') for c in s: - if (byte_ord(c) >= 32) and (byte_ord(c) <= 127): - out += c + i = byte_ord(c) + if 32 <= i <= 127: + out += byte_chr(i) else: - out += '%%%02X' % byte_ord(c) + out += b('%%%02X' % i) return out diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst index 07b0a468..1903f5cc 100644 --- a/sites/www/changelog.rst +++ b/sites/www/changelog.rst @@ -2,6 +2,10 @@ Changelog ========= +* :bug:`429` Server-level debug message logging was overlooked during the + Python 3 compatibility update; Python 3 clients attempting to log SSH debug + packets encountered type errors. This is now fixed. Thanks to ``@mjmaenpaa`` + for the catch. * :bug:`320` Update our win_pageant module to be Python 3 compatible. Thanks to ``@sherbang`` and ``@adamkerz`` for the patches. * :support:`378 backported` Minor code cleanup in the SSH config module diff --git a/tests/test_util.py b/tests/test_util.py index 44fb8ab5..7889aa7a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -26,8 +26,8 @@ import os from hashlib import sha1 import paramiko.util -from paramiko.util import lookup_ssh_host_config as host_config -from paramiko.py3compat import StringIO, byte_ord +from paramiko.util import lookup_ssh_host_config as host_config, safe_string +from paramiko.py3compat import StringIO, byte_ord, b from tests.util import ParamikoTest @@ -339,3 +339,14 @@ IdentityFile something_%l_using_fqdn config = paramiko.SSHConfig() config.parse(config_file) self.assertEqual(config.lookup("abcqwerty")["hostname"], "127.0.0.1") + + def test_safe_string(self): + vanilla = b("vanilla") + has_bytes = b("has \7\3 bytes") + safe_vanilla = safe_string(vanilla) + safe_has_bytes = safe_string(has_bytes) + expected_bytes = b("has %07%03 bytes") + err = "{0!r} != {1!r}" + assert safe_vanilla == vanilla, err.format(safe_vanilla, vanilla) + assert safe_has_bytes == expected_bytes, \ + err.format(safe_has_bytes, expected_bytes) |