From a08149d5f7aea1fcce55223a000ce9018df02961 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Wed, 12 Nov 2014 13:49:03 -0800 Subject: Failing test proving #429 --- tests/test_util.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index ecf8db72..0e7d0b2b 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -25,8 +25,8 @@ import errno import os from Crypto.Hash import SHA 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 @@ -344,3 +344,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) -- cgit v1.2.3 From b3d703e984f2046f8eb208e3c82f8bf5c7c49d6a Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Wed, 12 Nov 2014 13:54:01 -0800 Subject: Improve byte/string interactions in debug logging. Fixes #429 --- paramiko/transport.py | 2 +- paramiko/util.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/paramiko/transport.py b/paramiko/transport.py index 4b91a434..296d6eb7 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1985,7 +1985,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 dbcbbae4..542bb218 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 -- cgit v1.2.3 From ee06fc8f634b424b026afde3b853f8c321b1919f Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Wed, 12 Nov 2014 13:55:56 -0800 Subject: Changelog re #429 --- sites/www/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst index 91d4daa7..3f05caf7 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 -- cgit v1.2.3