Merge pull request #28 from nmathewson/fix_string_slice

[security] Fix a panic from an unchecked string slice.
This commit was merged in pull request #28.
This commit is contained in:
2021-11-14 13:45:34 -08:00
committed by GitHub

View File

@@ -505,7 +505,13 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result<Vec<ASN1Block>, ASN1Decode
let v = String::from_iter(body.iter().map(|x| *x as char)); let v = String::from_iter(body.iter().map(|x| *x as char));
let y = &v[0..2]; let y = match v.get(0..2) {
Some(yy) => yy,
None => {
// This wasn't a valid character boundrary.
return Err(ASN1DecodeErr::InvalidDateValue(v));
}
};
let y_prefix = match y.parse::<u8>() { let y_prefix = match y.parse::<u8>() {
Err(_) => return Err(ASN1DecodeErr::InvalidDateValue(v)), Err(_) => return Err(ASN1DecodeErr::InvalidDateValue(v)),
@@ -1438,6 +1444,15 @@ mod tests {
Ok(vec![ASN1Block::Integer(0, val)]) Ok(vec![ASN1Block::Integer(0, val)])
} }
#[test]
fn utc_time_tests() {
// Check for a regression against issue #27, in which this would
// cause a panic.
let input = [55, 13, 13, 133, 13, 13, 50, 13, 13, 133, 13, 13, 50, 13, 133];
let output = from_der(&input);
assert!(output.is_err());
}
#[test] #[test]
fn generalized_time_tests() { fn generalized_time_tests() {
check_spec( check_spec(