Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cert_storage): use u16::MAX for size checks #565

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions security/manager/ssl/cert_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,10 @@ struct Cert<'a> {

impl<'a> Cert<'a> {
fn new(der: &'a [u8], subject: &'a [u8], trust: i16) -> Result<Cert<'a>, SecurityStateError> {
if der.len() > u16::max as usize {
if der.len() > u16::MAX as usize {
return Err(SecurityStateError::from("certificate is too long"));
}
if subject.len() > u16::max as usize {
if subject.len() > u16::MAX as usize {
return Err(SecurityStateError::from("subject is too long"));
}
Ok(Cert {
Expand Down Expand Up @@ -961,12 +961,12 @@ impl<'a> Cert<'a> {
+ size_of::<i16>(),
);
bytes.write_u8(CERT_SERIALIZATION_VERSION_1)?;
if self.der.len() > u16::max as usize {
if self.der.len() > u16::MAX as usize {
return Err(SecurityStateError::from("certificate is too long"));
}
bytes.write_u16::<NetworkEndian>(self.der.len() as u16)?;
bytes.extend_from_slice(&self.der);
if self.subject.len() > u16::max as usize {
if self.subject.len() > u16::MAX as usize {
return Err(SecurityStateError::from("subject is too long"));
}
bytes.write_u16::<NetworkEndian>(self.subject.len() as u16)?;
Expand Down