From 0e6f028c3b6f9ce96e4abd3958923903b0ba6e65 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 14 Aug 2018 16:40:40 -0400 Subject: [PATCH] Err from get_route if the requested value is more than 21m BTC This fixes a potential overflow panic. --- src/ln/router.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ln/router.rs b/src/ln/router.rs index 727a58587..5aaea4f67 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -387,6 +387,10 @@ impl Router { return Err(HandleError{err: "Cannot generate a route to ourselves", action: None}); } + if final_value_msat > 21_000_000 * 1_0000_0000 * 1000 { + return Err(HandleError{err: "Cannot generate a route of more value than all existing satoshis", action: None}); + } + // We do a dest-to-source Dijkstra's sorting by each node's distance from the destination // plus the minimum per-HTLC fee to get from it to another node (aka "shitty A*"). // TODO: There are a few tweaks we could do, including possibly pre-calculating more stuff -- 2.39.5