diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2016-06-15 17:24:34 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2016-06-15 15:44:10 +0000 |
commit | ca96dbd651e483b64581d86698b0fa1568880374 (patch) | |
tree | 018195d066b3ffed92a3beaa92edb2a4c03f57b0 | |
parent | 320ffbca5673445ec059c1874e3855048da2d837 (diff) |
Prevent users from creating nonsensical Command properties.
Task-number: QBS-985
Change-Id: If25310b37ee35cf786ae8d0c19d2196129ac2ab1
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
5 files changed, 44 insertions, 1 deletions
diff --git a/src/lib/corelib/buildgraph/command.cpp b/src/lib/corelib/buildgraph/command.cpp index 210072ef4..ccfaa99fa 100644 --- a/src/lib/corelib/buildgraph/command.cpp +++ b/src/lib/corelib/buildgraph/command.cpp @@ -30,6 +30,7 @@ #include "command.h" #include <logging/translator.h> +#include <tools/error.h> #include <tools/hostosinfo.h> #include <tools/persistence.h> #include <tools/qbsassert.h> @@ -106,7 +107,12 @@ void AbstractCommand::applyCommandProperties(const QScriptValue *scriptValue) it.next(); if (m_predefinedProperties.contains(it.name())) continue; - m_properties.insert(it.name(), it.value().toVariant()); + const QVariant value = it.value().toVariant(); + if (QMetaType::Type(value.type()) == QMetaType::QObjectStar) { + throw ErrorInfo(Tr::tr("Property '%1' has a type unsuitable for storing in a command " + "object.").arg(it.name()), m_codeLocation); + } + m_properties.insert(it.name(), value); } } diff --git a/tests/auto/blackbox/testdata/invalid-command-property/input.txt b/tests/auto/blackbox/testdata/invalid-command-property/input.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/invalid-command-property/input.txt diff --git a/tests/auto/blackbox/testdata/invalid-command-property/invalid-command-property.qbs b/tests/auto/blackbox/testdata/invalid-command-property/invalid-command-property.qbs new file mode 100644 index 000000000..65437311e --- /dev/null +++ b/tests/auto/blackbox/testdata/invalid-command-property/invalid-command-property.qbs @@ -0,0 +1,27 @@ +import qbs +import qbs.TextFile + +Product { + type: ["output"] + Group { + files: ["input.txt"] + fileTags: ["input"] + } + Rule { + inputs: ["input"] + Artifact { + filePath: "dummy" + fileTags: ["output"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "Creating output"; + cmd.textFile = new TextFile(input.filePath, TextFile.ReadOnly); + cmd.sourceCode = function() { + var content = textFile.readAll(); + textFile.close(); + } + return [cmd]; + } + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 760c6250f..b6faa585a 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -2353,6 +2353,15 @@ void TestBlackbox::installTree() QVERIFY(QFile::exists(installRoot + "content/subdir2/baz.txt")); } +void TestBlackbox::invalidCommandProperty() +{ + QDir::setCurrent(testDataDir + "/invalid-command-property"); + QbsRunParameters params; + params.expectFailure = true; + QVERIFY(runQbs(params) != 0); + QVERIFY2(m_qbsStderr.contains("unsuitable"), m_qbsStderr.constData()); +} + static QProcessEnvironment processEnvironmentWithCurrentDirectoryInLibraryPath() { QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index dd190fa9d..286d4882b 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -147,6 +147,7 @@ private slots: void installedTransformerOutput(); void installPackage(); void installTree(); + void invalidCommandProperty(); void java(); void jsExtensionsFile(); void jsExtensionsFileInfo(); |