From 0cd1ea9537375bff23bb14d833c8a7e430923eef Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 24 Jun 2021 22:36:51 +0200 Subject: [PATCH] Avoid panic on invalid addr --- src/cmd/serve.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 53bcfcfa..8c06b257 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -286,7 +286,10 @@ pub fn serve( console::report_elapsed_time(start); // Stop right there if we can't bind to the address - let bind_address: SocketAddrV4 = address.parse().unwrap(); + let bind_address: SocketAddrV4 = match address.parse() { + Ok(a) => a, + Err(_) => return Err(format!("Invalid address: {}.", address).into()) + }; if (TcpListener::bind(&bind_address)).is_err() { return Err(format!("Cannot start server on address {}.", address).into()); }