]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Err from get_route if the requested value is more than 21m BTC
authorMatt Corallo <git@bluematt.me>
Tue, 14 Aug 2018 20:40:40 +0000 (16:40 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 17 Aug 2018 00:51:50 +0000 (20:51 -0400)
This fixes a potential overflow panic.

src/ln/router.rs

index 727a585879e9fcdb563636525c1c41ee8bf5d54f..5aaea4f67de130a8e64dcaf3a152d1ece433c741 100644 (file)
@@ -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