From f9cbdc252fa3b285afc1c1e1113e1f799dc803b8 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Fri, 7 Feb 2020 15:40:16 +0900 Subject: [PATCH] Improve connection.nim read error clarity when buffer overflow --- libp2p/connection.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libp2p/connection.nim b/libp2p/connection.nim index ce2c819..aaa2815 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -122,8 +122,10 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} = res = LP.getUVarint(buff.toOpenArray(0, i), length, size) if res == VarintStatus.Success: break - if res != VarintStatus.Success or size > DefaultReadSize: + if res != VarintStatus.Success: raise newInvalidVarintException() + if size > DefaultReadSize: + raise newLPStreamLimitError() buff.setLen(size) if size > 0.uint: trace "reading exact bytes from stream", size = size