diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-03-31 13:19:07 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-03-31 13:25:26 (GMT) |
commit | 2d13592054d1d6f049ecc1599913cb8c7541ef69 (patch) | |
tree | 9641ba999af5df2b09d4159dde924d21a2818a59 | |
parent | 9562f4a39ca9ca2c59bd621ac8e33af8b8006043 (diff) | |
download | Qt-2d13592054d1d6f049ecc1599913cb8c7541ef69.zip Qt-2d13592054d1d6f049ecc1599913cb8c7541ef69.tar.gz Qt-2d13592054d1d6f049ecc1599913cb8c7541ef69.tar.bz2 |
QProcess::start() segfaults on empty program
Handle cases where QProcess::start() and startDetached() are passed a
null, empty, or "invalid" program string instead of crashing.
Task-number: 247865
Reviewed-by: Andreas Aardal Hanssen
-rw-r--r-- | src/corelib/io/qprocess.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qprocess/tst_qprocess.cpp | 26 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index a9d8ee2..f16f996 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1601,6 +1601,13 @@ static QStringList parseCombinedArgString(const QString &program) void QProcess::start(const QString &program, OpenMode mode) { QStringList args = parseCombinedArgString(program); + if (args.isEmpty()) { + Q_D(QProcess); + d->processError = QProcess::FailedToStart; + setErrorString(tr("No program defined")); + emit error(d->processError); + return; + } QString prog = args.first(); args.removeFirst(); @@ -1769,6 +1776,8 @@ bool QProcess::startDetached(const QString &program, bool QProcess::startDetached(const QString &program) { QStringList args = parseCombinedArgString(program); + if (args.isEmpty()) + return false; QString prog = args.first(); args.removeFirst(); diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index f0dae5d..cb2b1bf 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -139,6 +139,8 @@ private slots: void switchReadChannels(); void setWorkingDirectory(); void startFinishStartFinish(); + void invalidProgramString_data(); + void invalidProgramString(); // keep these at the end, since they use lots of processes and sometimes // caused obscure failures to occur in tests that followed them (esp. on the Mac) @@ -2000,5 +2002,29 @@ void tst_QProcess::startFinishStartFinish() } } +//----------------------------------------------------------------------------- +void tst_QProcess::invalidProgramString_data() +{ + QTest::addColumn<QString>("programString"); + QTest::newRow("null string") << QString(); + QTest::newRow("empty string") << QString(""); + QTest::newRow("only blank string") << QString(" "); +} + +void tst_QProcess::invalidProgramString() +{ + QFETCH(QString, programString); + QProcess process; + + qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); + QSignalSpy spy(&process, SIGNAL(error(QProcess::ProcessError))); + + process.start(programString); + QCOMPARE(process.error(), QProcess::FailedToStart); + QCOMPARE(spy.count(), 1); + + QVERIFY(!QProcess::startDetached(programString)); +} + QTEST_MAIN(tst_QProcess) #include "tst_qprocess.moc" |