Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit ac6d9b3

Browse files
cdeckerrustyrussell
authored andcommitted
pylightning: Correctly return the remainder of a message back
We read a JSON message from the buffer, after converting it from raw bytes to UTF-8, and returning the remainder of the byte array back to the caller. However the return value of `raw_decode` refers to symbols in the UTF-8 decoded string, not the raw bytes underlying byte-array, which means that if we have multi-byte encoded UTF-8 symbols in the byte-array we end up with a misaligned offset and will return part of the message as remainder. This would then end up being interpreted as the result of the next call. This could not be exploited currently since we use a socket only for a single JSON-RPC call and will close the connection afterwards, but since we want to eventually recycle connections for multiple calls, this could have been very dangerous. Signed-off-by: Christian Decker <[email protected]> Reported-by: Corné Plooy <@bitonic-cjp>
1 parent 302a78f commit ac6d9b3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

contrib/pylightning/lightning/lightning.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def _readobj_compat(self, sock, buff=b''):
4646
continue
4747
# Convert late to UTF-8 so glyphs split across recvs do not
4848
# impact us
49-
objs, len_used = self.decoder.raw_decode(buff.decode("UTF-8"))
50-
return objs, buff[len_used:].lstrip()
49+
buff = buff.decode("UTF-8")
50+
objs, len_used = self.decoder.raw_decode(buff)
51+
buff = buff[len_used:].lstrip().encode("UTF-8")
52+
return objs, buff
5153
except ValueError:
5254
# Probably didn't read enough
5355
pass

0 commit comments

Comments
 (0)