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.6 6.5 Change-Id: I455fe22ef4ad4b2f9b01fffd17c7689095c39272 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 60bdf2b220151021e59baa372a050b9f72400b81) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
bdb713b1b7
commit
d24b0c05a4
@ -2277,6 +2277,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…
x
Reference in New Issue
Block a user