From 25ab750e3ade13633e56f0313b19b7e9fd4ff59e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 28 Aug 2020 10:27:59 +0200 Subject: [PATCH] qmake: Prevent injection of empty values via environment variables The qmake $() operator retrieves environment values at make time. In Qt Creator, we still use these values for feeding the code model, presumably because the qmake and make step share a common environment. However, we must take care that unset environment values do not lead to empty strings in qmake lists, as that can have unwanted side effects, especially when these lists get turned into command line arguments that are passed to build tools. A concrete example: A project file contained the following assignment: QMAKE_CXXFLAGS += $(SOME_VAR) SOME_VAR was not set in the environment, so an additional empty argument appeared on the command line when the code model called the MSVC compiler to retrieve some information required for parsing the code. The call failed, the code model had to fall back to default values, and the user got parsing errors. Fixes: QTCREATORBUG-21729 Change-Id: I224369a2fb9c0dd78406253edba03bd44556be44 Reviewed-by: Joerg Bornemann --- src/shared/proparser/profileevaluator.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index 3b816f01cd3..f6b2d3c5f31 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -71,8 +71,11 @@ QStringList ProFileEvaluator::values(const QString &variableName) const const ProStringList &values = d->values(ProKey(variableName)); QStringList ret; ret.reserve(values.size()); - foreach (const ProString &str, values) - ret << d->m_option->expandEnvVars(str.toQString()); + for (const ProString &str : values) { + const QString expanded = d->m_option->expandEnvVars(str.toQString()); + if (!expanded.isEmpty() || str.isEmpty()) + ret << expanded; + } return ret; }