From 752399ca6b7d8421901e978abb31a36c3fee72ff Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 Apr 2020 11:15:10 +0200 Subject: [PATCH] [libcalamares] Error out on empty command - an empty command isn't going to work (although it might successfully run chroot or env in the target system, that's not useful) - while here, move variable declarations closer to their use. --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 9e3cad4f9..d2f331919 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -124,7 +124,11 @@ System::runCommand( System::RunLocation location, const QString& stdInput, std::chrono::seconds timeoutSec ) { - QString output; + if ( args.isEmpty() ) + { + cWarning() << "Cannot run an empty program list"; + return ProcessResult::Code::FailedToStart; + } Calamares::GlobalStorage* gs = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; @@ -135,7 +139,6 @@ System::runCommand( System::RunLocation location, return ProcessResult::Code::NoWorkingDirectory; } - QProcess process; QString program; QStringList arguments( args ); @@ -156,6 +159,7 @@ System::runCommand( System::RunLocation location, program = "env"; } + QProcess process; process.setProgram( program ); process.setArguments( arguments ); process.setProcessChannelMode( QProcess::MergedChannels ); @@ -195,7 +199,7 @@ System::runCommand( System::RunLocation location, return ProcessResult::Code::TimedOut; } - output.append( QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed() ); + QString output = QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed(); if ( process.exitStatus() == QProcess::CrashExit ) {