From d22dca1bbc17ebc86cb7d7316aacf4b773c3150c Mon Sep 17 00:00:00 2001 From: Damien Caliste Date: Tue, 18 Sep 2018 16:58:44 +0200 Subject: Do not allow to pass full content type description to setType() method Nothing avoid or warn when calling setType("text/plain; charset=UTF-8"). Later calls to subType() or charset() return a wrong value then. Patch simply checks that ';' or '/' is not part of the argument in setType(). Change-Id: I1839c2a5800328e00f422054d5c19e9797be1a94 Reviewed-by: Pekka Vuorela Reviewed-by: Matthew Vogt --- src/libraries/qmfclient/qmailmessage.cpp | 10 +++++----- tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libraries/qmfclient/qmailmessage.cpp b/src/libraries/qmfclient/qmailmessage.cpp index a04abc67..b6f16ed2 100644 --- a/src/libraries/qmfclient/qmailmessage.cpp +++ b/src/libraries/qmfclient/qmailmessage.cpp @@ -2569,13 +2569,13 @@ QByteArray QMailMessageContentType::type() const */ void QMailMessageContentType::setType(const QByteArray& type) { - if (type.isEmpty()) - { + if (type.isEmpty()) { // Note - if there is a sub-type, setting type to null will destroy it setContent(type); - } - else - { + } else if (type.contains(';') || type.contains('/')) { + qWarning() << Q_FUNC_INFO << "wrong usage of setType(), consider using setSubType() or setParameter()" << type; + + } else { QByteArray content(type); QByteArray secondaryType(subType()); diff --git a/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp b/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp index 92c724cc..34d8ae63 100644 --- a/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp +++ b/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp @@ -1322,6 +1322,14 @@ void tst_QMailMessageContentType::setType() QCOMPARE( type2.type(), QByteArray() ); QCOMPARE( type2.subType(), QByteArray() ); QCOMPARE( type2.toString(), QByteArray("Content-Type:; charset=us-ascii") ); + + // Illegal arguments to setType() + QMailMessageContentType type3("image/jpeg"); + // Set the type and charset + type3.setType("text/plain; charset=UTF-8"); + QCOMPARE( type3.type(), QByteArray("image") ); + QCOMPARE( type3.subType(), QByteArray("jpeg") ); + QVERIFY( type3.charset().isEmpty() ); } void tst_QMailMessageContentType::subType() -- cgit v1.2.3