]> arthur.barton.de Git - bup.git/commitdiff
bup: make demux errors clearer
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 1 Feb 2021 23:01:47 +0000 (00:01 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sun, 13 Jun 2021 16:32:17 +0000 (11:32 -0500)
If we hit the

    assert(n <= MAX_PACKET)

in the demux code then quite likely we've been reading
something that shouldn't even be demuxed, but got some
error message from ssh instead of a muxed connection
record.

Clarify this case a bit by printing out the data that
we got (under the assumption it's an error message) and
raising Exception("Connection broken") instead of just
asserting.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py

index a6bfeebe2304276f381fa7bae44f097ed9c78506..a0679452a6e34c7514080db804d621fb99206d57 100644 (file)
@@ -590,7 +590,13 @@ class DemuxConn(BaseConn):
         assert(rl[0] == self.infd)
         ns = b''.join(checked_reader(self.infd, 5))
         n, fdw = struct.unpack('!IB', ns)
-        assert(n <= MAX_PACKET)
+        if n > MAX_PACKET:
+            # assume that something went wrong and print stuff
+            ns += os.read(self.infd, 1024)
+            stderr = byte_stream(sys.stderr)
+            stderr.write(ns)
+            stderr.flush()
+            raise Exception("Connection broken")
         if fdw == 1:
             self.reader = checked_reader(self.infd, n)
         elif fdw == 2: