Skip to content

Commit

Permalink
Check provided addr in outgoing stream
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
  • Loading branch information
rylev committed Dec 7, 2023
1 parent 02a4777 commit 0be2877
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/wasi/src/preview2/host/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl<T: WasiView> udp::HostUdpSocket for T {
remote_address,
family: socket.family,
send_state: SendState::Idle,
pool: socket.pool.clone(),
};

Ok((
Expand Down Expand Up @@ -451,7 +452,13 @@ impl<T: WasiView> udp::HostOutgoingDatagramStream for T {

let provided_addr = datagram.remote_address.map(SocketAddr::from);
let addr = match (stream.remote_address, provided_addr) {
(None, Some(addr)) => addr,
(None, Some(addr)) => {
// We don't actually use the connecter, we just use it to verify that `addr`
// is allowed. We only need to check the provided addr as the stream's remote
// address was checked when the stream was created.
let _ = stream.pool.udp_connecter(addr)?;
addr
}
(Some(addr), None) => addr,
(Some(connected_addr), Some(provided_addr)) if connected_addr == provided_addr => {
connected_addr
Expand All @@ -462,7 +469,6 @@ impl<T: WasiView> udp::HostOutgoingDatagramStream for T {
util::validate_remote_address(&addr)?;
util::validate_address_family(&addr, &stream.family)?;

// FIXME: check permission to send to `addr`.
if stream.remote_address == Some(addr) {
stream.inner.try_send(&datagram.data)?;
} else {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasi/src/preview2/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ pub struct OutgoingDatagramStream {
pub(crate) family: SocketAddressFamily,

pub(crate) send_state: SendState,

/// The pool of allowed addresses
pub(crate) pool: Arc<Pool>,
}

pub(crate) enum SendState {
Expand Down

0 comments on commit 0be2877

Please sign in to comment.