From f80cc060b9ff5e39098f8d1d6550b2e19d097178 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 25 Jan 2020 14:59:49 +0100 Subject: [PATCH] noise: Do not expect TlvPayloads without checking Suggested-by: @darosior --- noise/noise.py | 4 ++++ noise/test_chat.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/noise/noise.py b/noise/noise.py index 24655d0..fe07b1f 100755 --- a/noise/noise.py +++ b/noise/noise.py @@ -152,6 +152,10 @@ def recvmsg(plugin, request, last_id=None, **kwargs): @plugin.hook('htlc_accepted') def on_htlc_accepted(onion, htlc, plugin, **kwargs): payload = OnionPayload.from_hex(onion['payload']) + if not isinstance(payload, TlvPayload): + plugin.log("Payload is not a TLV payload") + return {'result': 'continue'} + msg = Message( id=len(plugin.messages), diff --git a/noise/test_chat.py b/noise/test_chat.py index 6d2e447..cff5914 100644 --- a/noise/test_chat.py +++ b/noise/test_chat.py @@ -82,3 +82,28 @@ def test_msg_and_keysend(node_factory, executor): # Check that l3 actually got the funds I sent it wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['msatoshi_to_us'] == amt) + + +def test_forward_ok(node_factory, executor): + """All nodes run plugin, forwarding node doesn't crash. + + Reproduces the crash mentioned by @darosior in this comment: + https://github.com/lightningd/plugins/pull/68#issuecomment-577251902 + + """ + opts = [{'plugin': plugin}]*3 + l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True, opts=opts) + + recv = executor.submit(l3.rpc.recvmsg) + l1.rpc.sendmsg(l3.info['id'], "Hello world!") + + # This one is tailing the incoming messages + m1 = recv.result(10) + + # This one should get the same result: + m2 = l3.rpc.recvmsg(last_id=-1) + # They should be the same :-) + assert(m1 == m2) + + assert(m2['sender'] == l1.info['id']) + assert(m2['verified'] == True)