Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
fix leaking connection due to reading unused value from handshake str…
Browse files Browse the repository at this point in the history
…ucture, #9656
  • Loading branch information
debris committed Oct 10, 2018
1 parent c313039 commit 292be72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
54 changes: 21 additions & 33 deletions util/network-devp2p/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ pub struct Handshake {
pub auth_cipher: Bytes,
/// A copy of received encrypted ack packet
pub ack_cipher: Bytes,
/// This Handshake is marked for deletion flag
pub expired: bool,
}

const V4_AUTH_PACKET_SIZE: usize = 307;
Expand All @@ -95,15 +93,9 @@ impl Handshake {
remote_version: PROTOCOL_VERSION,
auth_cipher: Bytes::new(),
ack_cipher: Bytes::new(),
expired: false,
})
}

/// Check if this handshake is expired.
pub fn expired(&self) -> bool {
self.expired
}

/// Start a handshake
pub fn start<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo, originated: bool) -> Result<(), Error> where Message: Send + Clone+ Sync + 'static {
self.originated = originated;
Expand All @@ -125,38 +117,34 @@ impl Handshake {

/// Readable IO handler. Drives the state change.
pub fn readable<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), Error> where Message: Send + Clone + Sync + 'static {
if !self.expired() {
while let Some(data) = self.connection.readable()? {
match self.state {
HandshakeState::New => {},
HandshakeState::StartSession => {},
HandshakeState::ReadingAuth => {
self.read_auth(io, host.secret(), &data)?;
},
HandshakeState::ReadingAuthEip8 => {
self.read_auth_eip8(io, host.secret(), &data)?;
},
HandshakeState::ReadingAck => {
self.read_ack(host.secret(), &data)?;
},
HandshakeState::ReadingAckEip8 => {
self.read_ack_eip8(host.secret(), &data)?;
},
}
if self.state == HandshakeState::StartSession {
io.clear_timer(self.connection.token).ok();
break;
}
while let Some(data) = self.connection.readable()? {
match self.state {
HandshakeState::New => {},
HandshakeState::StartSession => {},
HandshakeState::ReadingAuth => {
self.read_auth(io, host.secret(), &data)?;
},
HandshakeState::ReadingAuthEip8 => {
self.read_auth_eip8(io, host.secret(), &data)?;
},
HandshakeState::ReadingAck => {
self.read_ack(host.secret(), &data)?;
},
HandshakeState::ReadingAckEip8 => {
self.read_ack_eip8(host.secret(), &data)?;
},
}
if self.state == HandshakeState::StartSession {
io.clear_timer(self.connection.token).ok();
break;
}
}
Ok(())
}

/// Writable IO handler.
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<(), Error> where Message: Send + Clone + Sync + 'static {
if !self.expired() {
self.connection.writable(io)?;
}
self.connection.writable(io)?;
Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions util/network-devp2p/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ impl Session {

/// Check if this session is expired.
pub fn expired(&self) -> bool {
match self.state {
State::Handshake(ref h) => self.expired || h.expired(),
_ => self.expired,
}
self.expired
}

/// Check if this session is over and there is nothing to be sent.
Expand Down

0 comments on commit 292be72

Please sign in to comment.