From c8d9b17367cfdcb034d11f8a168ca4ae3993e7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Tue, 13 Aug 2013 13:20:05 +0200 Subject: Fix crash in QProcess::waitForStarted() on Unix. Invoking waitForStarted() on a QProcess before or after an unsuccessful call to start() (e.g., with an empty command), would execute FD_SET with an invalid file descriptor and cause the process to abort. The bug can be reliably reproduced on OSX. Task-number: QTBUG-32958 Change-Id: Id25b7781168489281645e21571361ca1a71d43e3 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess.cpp | 6 +++--- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 1be108d0a7..96cec568df 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1691,10 +1691,10 @@ QProcessEnvironment QProcess::processEnvironment() const bool QProcess::waitForStarted(int msecs) { Q_D(QProcess); - if (d->processState == QProcess::Running) - return true; + if (d->processState == QProcess::Starting) + return d->waitForStarted(msecs); - return d->waitForStarted(msecs); + return d->processState == QProcess::Running; } /*! \reimp diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index f2759dfd6e..7a3f6837f8 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -154,6 +154,7 @@ private slots: void invalidProgramString(); void onlyOneStartedSignal(); void finishProcessBeforeReadingDone(); + void waitForStartedWithoutStart(); // 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) @@ -2214,6 +2215,12 @@ void tst_QProcess::finishProcessBeforeReadingDone() QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); } +void tst_QProcess::waitForStartedWithoutStart() +{ + QProcess process; + QVERIFY(!process.waitForStarted(5000)); +} + #endif //QT_NO_PROCESS QTEST_MAIN(tst_QProcess) -- cgit v1.2.3