IPC: disallow unknown queries in QNativeIpcKey string form

So we can add them in the future but cause older versions of Qt to
reject them if they don't know what they are.

Pick-to: 6.6 6.6.0
Change-Id: I512648fd617741199e67fffd1782b85935bb832a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
bb10
Thiago Macieira 2023-09-07 13:38:23 -07:00
parent eb5c5a76cf
commit 18867845eb
2 changed files with 7 additions and 4 deletions

View File

@ -555,7 +555,7 @@ QNativeIpcKey QNativeIpcKey::fromString(const QString &text)
Type invalidType = {};
Type type = stringToType(u.scheme());
if (type == invalidType || !u.isValid() || !u.userInfo().isEmpty() || !u.host().isEmpty()
|| u.port() != -1)
|| u.port() != -1 || u.hasQuery())
return QNativeIpcKey(invalidType);
QNativeIpcKey result(QString(), type);
@ -564,6 +564,7 @@ QNativeIpcKey QNativeIpcKey::fromString(const QString &text)
// decode the payload
result.setNativeKey(u.path());
return result;
}

View File

@ -280,12 +280,14 @@ void tst_QNativeIpcKey::fromString_data()
<< "posix:%C4%80.%E2%80%80.%F0%90%80%80"
<< QNativeIpcKey(u"\u0100.\u2000.\U00010000"_s, QNativeIpcKey::Type::PosixRealtime);
// query and fragment are ignored
QTest::addRow("with-query") << "posix:/foo?bar" << valid;
// fragments are ignored
QTest::addRow("with-fragment") << "posix:/foo#bar" << valid;
QTest::addRow("with-queryfragment") << "posix:/foo?bar#baz" << valid;
QTest::addRow("with-fragmentquery") << "posix:/foo#bar?baz" << valid;
// but unknown query items are not
QTest::addRow("with-query") << "posix:/foo?bar" << invalid;
QTest::addRow("with-queryfragment") << "posix:/foo?bar#baz" << invalid;
// add some ones that won't parse well
QTest::addRow("positive-number") << "81" << invalid;
QTest::addRow("negative-number") << "-81" << invalid;