From 00883af0a919c55b25d4969155fd989eab772a5a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 30 Sep 2021 17:30:44 +1000 Subject: [PATCH] Don't panic on unexpected messages This is actually a security bug as it would allow remote triggers of panics! --- daemon/src/maker_cfd.rs | 6 +++--- daemon/src/taker_cfd.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 5f2883d..2b285a1 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -154,9 +154,9 @@ impl Actor { SetupState::Active { taker, .. } => { anyhow::bail!("Currently setting up contract with taker {}", taker) } - SetupState::None => unreachable!( - "`SetupState` is guaranteed to be `Active` before anyone sends a message" - ), + SetupState::None => { + anyhow::bail!("Received setup message without an active contract setup"); + } } Ok(()) diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index 7e75828..ba1b59a 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -220,7 +220,9 @@ impl Actor { SetupState::Active { sender } => { sender.send(msg).await?; } - SetupState::None => anyhow::bail!("OrderAccepted message should arrive first"), + SetupState::None => { + anyhow::bail!("Received setup message without an active contract setup") + } } Ok(())