Skip to content

Commit

Permalink
Bounds-check port number
Browse files Browse the repository at this point in the history
  • Loading branch information
nightkr committed Jan 16, 2024
1 parent fa5fe56 commit 351aea6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
num::TryFromIntError,
};

use futures::future::try_join_all;
Expand Down Expand Up @@ -79,6 +80,12 @@ pub enum Error {
listener: ObjectRef<Listener>,
pod: ObjectRef<Pod>,
},
#[snafu(display("port {port} ({port_name:?}) is out of bounds, must be within {range:?}", range = 0..=u16::MAX))]
PortOutOfBounds {
source: TryFromIntError,
port_name: String,
port: i32,
},
}

/// An HDFS cluster stacklet. This resource is managed by the Stackable operator for Apache Hadoop HDFS.
Expand Down Expand Up @@ -609,8 +616,14 @@ impl HdfsCluster {
ports: listener_address
.ports
.into_iter()
.map(|(k, v)| (k, v as u16))
.collect(),
.map(|(port_name, port)| {
let port = u16::try_from(port).context(PortOutOfBoundsSnafu {
port_name: &port_name,
port,
})?;
Ok((port_name, port))
})
.collect::<Result<_, _>>()?,
..pod_ref
})
}))
Expand Down

0 comments on commit 351aea6

Please sign in to comment.