QProcess: fix startCommand() with whitespace-only strings
We'd end up trying to takeFirst() from an empty QStringList. [ChangeLog][QtCore][QProcess] Fixed a bug that would cause startCommand() to crash if passed a string that was empty or contained only whitespace characters. Fixes: QTBUG-124512 Pick-to: 6.5 6.6 6.7 Change-Id: I455fe22ef4ad4b2f9b01fffd17c7689095c39272 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>bb10
parent
8d549c3365
commit
60bdf2b220
|
|
@ -2281,6 +2281,10 @@ void QProcess::start(OpenMode mode)
|
|||
void QProcess::startCommand(const QString &command, OpenMode mode)
|
||||
{
|
||||
QStringList args = splitCommand(command);
|
||||
if (args.isEmpty()) {
|
||||
qWarning("QProcess::startCommand: empty or whitespace-only command was provided");
|
||||
return;
|
||||
}
|
||||
const QString program = args.takeFirst();
|
||||
start(program, args, mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ private slots:
|
|||
void constructing();
|
||||
void simpleStart();
|
||||
void startCommand();
|
||||
void startCommandEmptyString();
|
||||
void startWithOpen();
|
||||
void startWithOldOpen();
|
||||
void execute();
|
||||
|
|
@ -299,6 +300,25 @@ void tst_QProcess::startCommand()
|
|||
QCOMPARE(actual, expected);
|
||||
}
|
||||
|
||||
void tst_QProcess::startCommandEmptyString()
|
||||
{
|
||||
static const char warningMsg[] =
|
||||
"QProcess::startCommand: empty or whitespace-only command was provided";
|
||||
QProcess process;
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, warningMsg);
|
||||
process.startCommand("");
|
||||
QVERIFY(!process.waitForStarted());
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, warningMsg);
|
||||
process.startCommand(" ");
|
||||
QVERIFY(!process.waitForStarted());
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, warningMsg);
|
||||
process.startCommand("\t\n");
|
||||
QVERIFY(!process.waitForStarted());
|
||||
}
|
||||
|
||||
void tst_QProcess::startWithOpen()
|
||||
{
|
||||
QProcess p;
|
||||
|
|
|
|||
Loading…
Reference in New Issue