fix(tls): reject non-ASCII certificate validity times instead of panicking

parse_asn1_time_string sliced the time by byte offset, so a multi-byte
UTF-8 character in a hostile certificate put a boundary inside it and
panicked, aborting the sweep. Found by cargo fuzz.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-03 10:53:26 -03:00
1 parent 3b91f77b27
commit 0d4fe01baf
1 file changed
+5
+5
View File
@@ -200,6 +200,11 @@ fn read_der_len(data: &[u8], offset: usize) -> Result<(usize, usize), String> {
}
fn parse_asn1_time_string(s: &str, is_utc: bool) -> Result<DateTime<Utc>, String> {
// The fields below are sliced by byte offset; a multi-byte character from a
// hostile certificate would put a slice boundary inside it and panic.
if !s.is_ascii() {
return Err(format!("ASN.1 time is not ASCII: '{s}'"));
}
let clean = s.trim_end_matches('Z');
if is_utc {
// YYMMDDHHMMSS