From 7853424a62744939740ea7f4dfcae8b84a8b1a78 Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Fri, 24 Aug 2018 12:14:49 -0300 Subject: [PATCH] Use std::find instead of iterating to search in allowedCommands. --- src/util/externalcommandhelper.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp index c3f7c72..0c701e2 100644 --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -288,16 +288,11 @@ QVariantMap ExternalCommandHelper::start(const QByteArray& signature, const quin // Compare with command whitelist QString basename = command.mid(command.lastIndexOf(QLatin1Char('/')) + 1); - bool success = false; - for (const auto& command : allowedCommands) { - if (basename == command) { - success = true; - break; - } - } - if ( !success ) { + if (std::find(std::begin(allowedCommands), std::end(allowedCommands), basename) == std::end(allowedCommands)) { // TODO: notify the user m_loop->exit(); + reply[QStringLiteral("success")] = false; + return reply; } // connect(&cmd, &QProcess::readyReadStandardOutput, this, &ExternalCommandHelper::onReadOutput);