QCryptographicHash: check addData() with null QByteArrayView

When this code was using QByteArray, whose data() is never nullptr,
the strings presented to the underlying C APIs were always valid NTSs
(nullptr is not a valid NTS).

With QByteArrayView, or with QT5_NULL_STRINGS != 1, this is no longer
the case. Check that all implementations are fine with that.

Pick-to: 6.5 6.4
Change-Id: I78251288a4784440af4a2daf095aed7c53867287
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2023-03-02 19:45:04 +01:00
parent e80fc16cec
commit 96dc4acb23

View File

@ -31,6 +31,8 @@ private slots:
void files();
void hashLength_data();
void hashLength();
void addDataAcceptsNullByteArrayView_data() { hashLength_data(); }
void addDataAcceptsNullByteArrayView();
void move();
void swap();
// keep last
@ -414,6 +416,27 @@ void tst_QCryptographicHash::hashLength()
QCOMPARE(QCryptographicHash::hashLength(algorithm), expectedSize);
}
void tst_QCryptographicHash::addDataAcceptsNullByteArrayView()
{
QFETCH(const QCryptographicHash::Algorithm, algorithm);
if (!QCryptographicHash::supportsAlgorithm(algorithm))
QSKIP("QCryptographicHash doesn't support this algorithm");
QCryptographicHash hash1(algorithm);
hash1.addData("meep");
hash1.addData(QByteArrayView{}); // after other data
QCryptographicHash hash2(algorithm);
hash2.addData(QByteArrayView{}); // before any other data
hash2.addData("meep");
const auto expected = QCryptographicHash::hash("meep", algorithm);
QCOMPARE(hash1.resultView(), expected);
QCOMPARE(hash2.resultView(), expected);
}
void tst_QCryptographicHash::move()
{
QCryptographicHash hash1(QCryptographicHash::Sha1);