From 6086038b01277b42429a18ef5adb5de1b60cfc05 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 6 Sep 2019 15:25:28 -0600 Subject: [PATCH] raise correct LP exception on incomplete data --- libp2p/connection.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libp2p/connection.nim b/libp2p/connection.nim index 087f6ee2a..91be78e80 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -8,9 +8,12 @@ ## those terms. import chronos, options -import peerinfo, multiaddress, - stream/lpstream, peerinfo, - varint, vbuffer +import peerinfo, + multiaddress, + stream/lpstream, + peerinfo, + varint, + vbuffer const DefaultReadSize*: uint = 64 * 1024 @@ -96,9 +99,11 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} = result = buffer return buffer.setLen(size) - await s.readExactly(addr buffer[0], int(size)) + if size > 0.uint: + await s.readExactly(addr buffer[0], int(size)) except TransportIncompleteError: buffer.setLen(0) + raise newLPStreamIncompleteError() result = buffer