tor-cell: Consistent and secure conversion to u16

This commit improves the overflow protection of one call to
Vec::write_u16(), by replacing the cast conversion from self.sig.len()
with a call to u16::try_from(), like it is already done in the rest of
the accompanying function.
This commit is contained in:
Emil Engler 2022-10-24 14:40:51 +02:00
parent b031616b5f
commit c42a55d515
No known key found for this signature in database
GPG Key ID: 2F6D4145C55FC7C7
1 changed files with 1 additions and 1 deletions

View File

@ -194,7 +194,7 @@ impl msg::Body for EstablishIntro {
}
w.write_all(&self.handshake_auth[..]);
w.write_u16(self.sig.len() as u16);
w.write_u16(u16::try_from(self.sig.len()).map_err(|_| EncodeError::BadLengthValue)?);
w.write_all(&self.sig[..]);
Ok(())
}