From 299186602a3ad5c7cec0879170901ffcda673414 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 20 May 2020 15:59:45 +0200 Subject: [PATCH] Add a test and remove a work-around for a fixed bug The ASN.1 parser for a date-time had to check the date-time string was all digits to catch the case of a sign in the month field, which used to be accepted when it should not be. That bug has now been fixed, so remove the work-around and add a second date-time test-case, renaming (and modernising) the existing one for consistency. Task-number: QTBUG-84349 Change-Id: I649c5129312b6865af08b22ba6893cb4e29243f8 Reviewed-by: Giuseppe D'Angelo --- src/plugins/tls/shared/qasn1element.cpp | 7 ------- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 9 +++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/plugins/tls/shared/qasn1element.cpp b/src/plugins/tls/shared/qasn1element.cpp index 3df76c3774..de5f70a585 100644 --- a/src/plugins/tls/shared/qasn1element.cpp +++ b/src/plugins/tls/shared/qasn1element.cpp @@ -261,13 +261,6 @@ QDateTime QAsn1Element::toDateTime() const if (mValue.back() != 'Z') return result; - // In addition, check that we only have digits representing the - // date/time. This should not really be necessary (there's no such - // thing as negative months/days/etc.); it's a workaround for - // QTBUG-84349. - if (!std::all_of(mValue.begin(), mValue.end() - 1, isAsciiDigit)) - return result; - if (mType == UtcTimeType && mValue.size() == 13) { result = QDateTime::fromString(QString::fromLatin1(mValue), QStringLiteral("yyMMddHHmmsst")); diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 553b639ebd..13d9d4ffe5 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2908,10 +2908,11 @@ void tst_QDateTime::fromStringStringFormat_data() << QString(u8"yyyy🤣MM🤣ddThh🤣mm🤣ss.zt") << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); - // QTBUG-84349 - QTest::newRow("QTBUG-84349: positive sign in month") - << QStringLiteral("9922+221102233Z") << QStringLiteral("yyyyMMddHHmmsst") - << QDateTime(); + // Two tests derived from malformed ASN.1 strings (QTBUG-84349): + QTest::newRow("ASN.1:UTC") + << u"22+221102233Z"_qs << u"yyMMddHHmmsst"_qs << QDateTime(); + QTest::newRow("ASN.1:Generalized") + << u"9922+221102233Z"_qs << u"yyyyMMddHHmmsst"_qs << QDateTime(); // fuzzer test QTest::newRow("integer overflow found by fuzzer")