diff --git a/Tests/LibCrypto/TestASN1.cpp b/Tests/LibCrypto/TestASN1.cpp index 6c766b787e5..e18b61174dc 100644 --- a/Tests/LibCrypto/TestASN1.cpp +++ b/Tests/LibCrypto/TestASN1.cpp @@ -57,10 +57,9 @@ TEST_CASE(test_utc_missing_z) // YYMMDDhhmm[ss] // We don't actually need to parse this correctly; rejecting these inputs is fine. // This test just makes sure that we don't crash. - // FIXME: This currently crashes - // (void)Crypto::ASN1::parse_utc_time("010101010101"sv); - // (void)Crypto::ASN1::parse_utc_time("010203040506"sv); - // (void)Crypto::ASN1::parse_utc_time("020406081012"sv); - // (void)Crypto::ASN1::parse_utc_time("0204060810"sv); - // (void)Crypto::ASN1::parse_utc_time("220911220000"sv); + (void)Crypto::ASN1::parse_utc_time("010101010101"sv); + (void)Crypto::ASN1::parse_utc_time("010203040506"sv); + (void)Crypto::ASN1::parse_utc_time("020406081012"sv); + (void)Crypto::ASN1::parse_utc_time("0204060810"sv); + (void)Crypto::ASN1::parse_utc_time("220911220000"sv); } diff --git a/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp b/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp index 8acf1f37f07..a585646293b 100644 --- a/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp +++ b/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp @@ -84,26 +84,25 @@ Optional parse_utc_time(StringView time) auto minute = lexer.consume(2).to_uint(); Optional seconds, offset_hours, offset_minutes; [[maybe_unused]] bool negative_offset = false; - if (!lexer.next_is('Z')) { - if (!lexer.next_is(is_any_of("+-"sv))) { - seconds = lexer.consume(2).to_uint(); - if (!seconds.has_value()) { - return {}; - } - } - if (lexer.next_is(is_any_of("+-"sv))) { - negative_offset = lexer.consume() == '-'; - offset_hours = lexer.consume(2).to_uint(); - offset_minutes = lexer.consume(2).to_uint(); - if (!offset_hours.has_value() || !offset_minutes.has_value()) { - return {}; - } - } else { - lexer.consume(); + if (lexer.next_is(is_any_of("0123456789"sv))) { + seconds = lexer.consume(2).to_uint(); + if (!seconds.has_value()) { + return {}; + } + } + + if (lexer.next_is('Z')) { + lexer.consume(); + } else if (lexer.next_is(is_any_of("+-"sv))) { + negative_offset = lexer.consume() == '-'; + offset_hours = lexer.consume(2).to_uint(); + offset_minutes = lexer.consume(2).to_uint(); + if (!offset_hours.has_value() || !offset_minutes.has_value()) { + return {}; } } else { - lexer.consume(); + return {}; } if (!year_in_century.has_value() || !month.has_value() || !day.has_value() || !hour.has_value() || !minute.has_value()) {