Skip to content

Commit

Permalink
Fix mirrord making double bind of port 0 fail (metalbear-co#2811)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha authored Oct 9, 2024
1 parent 4f82caa commit ee0b9ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/+fix-double-bind-zero.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mirrord making double bind of port 0 fail
20 changes: 11 additions & 9 deletions mirrord/layer/src/socket/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,17 @@ pub(super) fn bind(
// Check if the user's requested address isn't already in use, even though it's not actually
// bound, as we bind to a different address, but if we don't check for this then we're
// changing normal socket behavior (see issue #1123).
if SOCKETS
.lock()?
.iter()
.any(|(_, socket)| match &socket.state {
SocketState::Initialized | SocketState::Connected(_) => false,
SocketState::Bound(bound) | SocketState::Listening(bound) => {
bound.requested_address == requested_address
}
})
// We check that port isn't 0 because if it's port 0 it can't really conflict.
if requested_address.port() != 0
&& SOCKETS
.lock()?
.iter()
.any(|(_, socket)| match &socket.state {
SocketState::Initialized | SocketState::Connected(_) => false,
SocketState::Bound(bound) | SocketState::Listening(bound) => {
bound.requested_address == requested_address
}
})
{
Err(HookError::AddressAlreadyBound(requested_address))?;
}
Expand Down

0 comments on commit ee0b9ff

Please sign in to comment.