diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2024-05-08 16:56:10 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2024-05-10 11:37:31 +0000 |
commit | 67af0c9517b01c482f425a6761b1cf38c486d3c3 (patch) | |
tree | 07030249a09a77fc761fc6e03dffdbe5e523bf4a /src/lib/corelib/buildgraph | |
parent | d18ee709b39865162006d04243d7fbc13d7a3296 (diff) |
RulesApplicator: Do not auto-correct invalid artifact paths
If a rule tries to create an artifact outside the build directory,
complain instead of (sometimes) silently changing it.
Fixes: QBS-1268
Change-Id: I9b5e27cf01b01fd7d09254083279682888838f83
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'src/lib/corelib/buildgraph')
-rw-r--r-- | src/lib/corelib/buildgraph/rulesapplicator.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/lib/corelib/buildgraph/rulesapplicator.cpp b/src/lib/corelib/buildgraph/rulesapplicator.cpp index e07abd74a..94cee0c62 100644 --- a/src/lib/corelib/buildgraph/rulesapplicator.cpp +++ b/src/lib/corelib/buildgraph/rulesapplicator.cpp @@ -420,11 +420,7 @@ RulesApplicator::OutputArtifactInfo RulesApplicator::createOutputArtifactFromRul RulesApplicator::OutputArtifactInfo RulesApplicator::createOutputArtifact(const QString &filePath, const FileTags &fileTags, bool alwaysUpdated, const ArtifactSet &inputArtifacts) { - QString outputPath = filePath; - // don't let the output artifact "escape" its build dir - outputPath.replace(StringConstants::dotDot(), QStringLiteral("dotdot")); - outputPath = resolveOutPath(outputPath); - + const QString outputPath = resolveOutPath(filePath); if (m_rule->isDynamic()) { const Set<FileTag> undeclaredTags = fileTags - m_rule->collectedOutputFileTags(); if (!undeclaredTags.empty()) { @@ -676,9 +672,14 @@ Artifact *RulesApplicator::createOutputArtifactFromScriptValue(const JSValue &ob QString RulesApplicator::resolveOutPath(const QString &path) const { - QString buildDir = m_product->topLevelProject()->buildDirectory; - QString result = FileInfo::resolvePath(buildDir, path); - result = QDir::cleanPath(result); + const QString buildDir = m_product->topLevelProject()->buildDirectory; + QString result = QDir::cleanPath(FileInfo::resolvePath(buildDir, path)); + if (!result.startsWith(buildDir + QLatin1Char('/'))) { + throw ErrorInfo( + Tr::tr("Refusing to create artifact '%1' outside of build directory '%2'.") + .arg(QDir::toNativeSeparators(result), QDir::toNativeSeparators(buildDir)), + m_rule->prepareScript.location()); + } return result; } |