]> arthur.barton.de Git - bup.git/commitdiff
ssh: don't pass through bad BUP_TTY_WIDTH
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 21 Dec 2020 20:45:55 +0000 (21:45 +0100)
committerRob Browning <rlb@defaultvalue.org>
Thu, 24 Dec 2020 01:16:56 +0000 (19:16 -0600)
If there's no BUP_TTY_WIDTH variable already, then environ.get()
will result in None, which cannot be converted to an integer so
we get 0. Then we pass 0 to the other side in the BUP_TTY_WIDTH
environment variable.

Unfortunately, 0 is a really bad default, since textwrap cannot
work with a width of 0, causing tracebacks such as the one Mark
J Hewitt reported:
https://groups.google.com/g/bup-list/c/rfIw3STN2EY/m/C5Y3UrMIAgAJ

Fix this by not passing it through if there's no good value.

Reported-by: Mark J Hewitt <mjh@idnet.com>
Reported-by: Alexander Barton <alex@barton.de>
Fixes: cd3647c81a25 ("bup: pass TTY width through to sub-command and remote")
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/ssh.py

index 643b5089965b4c0aa6116818bcaab3af9377d4d2..7f178a69dc2ca0101563e283878b0d3e326ceec3 100644 (file)
@@ -16,9 +16,13 @@ def connect(rhost, port, subcmd, stderr=None):
     else:
         buglvl = helpers.atoi(environ.get(b'BUP_DEBUG'))
         force_tty = helpers.atoi(environ.get(b'BUP_FORCE_TTY'))
-        tty_width = helpers.atoi(environ.get(b'BUP_TTY_WIDTH'))
+        tty_width = environ.get(b'BUP_TTY_WIDTH', None)
+        if tty_width is not None:
+            tty_width = b'BUP_TTY_WIDTH=%d' % helpers.atoi(tty_width)
+        else:
+            tty_width = b''
         cmd = b"""
-                   sh -c 'BUP_DEBUG=%d BUP_FORCE_TTY=%d BUP_TTY_WIDTH=%d bup %s'
+                   sh -c 'BUP_DEBUG=%d BUP_FORCE_TTY=%d %s bup %s'
                """ % (buglvl, force_tty, tty_width, subcmd)
         argv = [b'ssh']
         if port: