From a0a86ffbf262fcb91dd602572fa3529884790ce3 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Wed, 2 Oct 2024 10:27:37 +0200 Subject: [PATCH] Fix #423: Shield against empty array access after dead peer Signed-off-by: Lee Smet --- CHANGELOG.md | 11 ++++++++--- mycelium/src/router.rs | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e09afe..895859a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,18 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix a panic in the route cleanup task when a peer dies who is the last stored + announcer of a subnet. + ## [0.5.5] - 2024-09-27 ### Added - Mycelium-ui, a standalone GUI which exposes (part of) the mycelium API. This - does __not__ have a bundled mycelium node, so that needs to be run separately. - + does **not** have a bundled mycelium node, so that needs to be run separately. + ### Changed - Default TUN name on Linux and Windows is now `mycelium`. On MacOS it is now `utun0`. - TUN interface name validation on MacOS. If the user supplies an invalid or already -taken interface name, an available interface name will be automatically assigned. + taken interface name, an available interface name will be automatically assigned. ### Fixed diff --git a/mycelium/src/router.rs b/mycelium/src/router.rs index 98f42fe..236e214 100644 --- a/mycelium/src/router.rs +++ b/mycelium/src/router.rs @@ -372,6 +372,8 @@ where // If there is no selected route there is nothing to do here. We keep expired routes in the // table for a while so updates of those should already have propagated to peers. let route_list = routes.routes(); + // If we have a new selected route we must have at least 1 item in the route list so + // accessing the 0th list element here is fine. if let Some(new_selected) = self.find_best_route(&route_list).cloned() { if new_selected.neighbour() == route_list[0].neighbour() && route_list[0].selected() { debug!( @@ -389,7 +391,7 @@ where } routes.set_selected(new_selected.neighbour()); - } else if route_list[0].selected() { + } else if !route_list.is_empty() && route_list[0].selected() { // This means we went from a selected route to a non-selected route. Unselect route and // trigger update. // At this point we also send a seqno request to all peers which advertised this route