From 01f800ae6f8611a4218b7bbf5953dc896cac5767 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 13 Jul 2015 03:41:33 -0700 Subject: [PATCH] Add a macro to disable use of potentially dangerous QProcess APIs. Change-Id: Id1ac19b1f4077ec2ea6f998883653e58ff77a8b6 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 27 +++++++++++++++++++++++++++ src/corelib/io/qprocess.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 17079bd1cc..06a4880fdb 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -100,6 +100,19 @@ QT_END_NAMESPACE QT_BEGIN_NAMESPACE +/*! + \since 5.6 + + \macro QT_NO_PROCESS_COMBINED_ARGUMENT_START + \relates QProcess + + Disables the QProcess::start() overload taking a single string. + In most cases where it is used, the user intends for the first argument + to be treated atomically as per the other overload. + + \sa start() +*/ + /*! \class QProcessEnvironment \inmodule QtCore @@ -2262,7 +2275,20 @@ static QStringList parseCombinedArgString(const QString &program) After the \a command string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list. + You can disable this overload by defining \c + QT_NO_PROCESS_COMBINED_ARGUMENT_START when you compile your applications. + This can be useful if you want to ensure that you are not splitting arguments + unintentionally, for example. In virtually all cases, using the other overload + is the preferred method. + + On operating systems where the system API for passing command line + arguments to a subprocess natively uses a single string (Windows), one can + conceive command lines which cannot be passed via QProcess's portable + list-based API. In these rare cases you need to use setProgram() and + setNativeArguments() instead of this function. + */ +#if !defined(QT_NO_PROCESS_COMBINED_ARGUMENT_START) void QProcess::start(const QString &command, OpenMode mode) { QStringList args = parseCombinedArgString(command); @@ -2277,6 +2303,7 @@ void QProcess::start(const QString &command, OpenMode mode) start(prog, args, mode); } +#endif /*! \since 5.0 diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index 21421e1184..f95358250e 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -147,7 +147,9 @@ public: virtual ~QProcess(); void start(const QString &program, const QStringList &arguments, OpenMode mode = ReadWrite); +#if !defined(QT_NO_PROCESS_COMBINED_ARGUMENT_START) void start(const QString &command, OpenMode mode = ReadWrite); +#endif void start(OpenMode mode = ReadWrite); bool open(OpenMode mode = ReadWrite) Q_DECL_OVERRIDE;