From 92af1dad0652951e8f7adc1a4a59527bd98435fa Mon Sep 17 00:00:00 2001 From: David Cole Date: Fri, 18 Nov 2011 17:13:07 -0500 Subject: [PATCH] CTest: Disallow problem chars in build and site names (#11792) Also, use "(empty)" rather than actually sending an empty string if build or site name is not set properly. --- Source/cmCTest.cxx | 57 +++++++++++++++++++++++++++++++++++++++++----- Source/cmCTest.h | 4 ++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 7bb8b27fa..14055a457 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1440,6 +1440,43 @@ int cmCTest::RunTest(std::vector argv, return result; } +//---------------------------------------------------------------------- +std::string cmCTest::SafeBuildIdField(const std::string& value) +{ + std::string safevalue(value); + + if (safevalue != "") + { + // Disallow non-filename and non-space whitespace characters. + // If they occur, replace them with "" + // + const char *disallowed = "\\/:*?\"<>|\n\r\t\f\v"; + + if (safevalue.find_first_of(disallowed) != value.npos) + { + std::string::size_type i = 0; + std::string::size_type n = strlen(disallowed); + char replace[2]; + replace[1] = 0; + + for (i= 0; iGetCTestConfiguration("BuildName")); + std::string stamp = cmCTest::SafeBuildIdField( + this->CurrentTag + "-" + this->GetTestModelString()); + std::string site = cmCTest::SafeBuildIdField( + this->GetCTestConfiguration("Site")); + ostr << "\n" - << "GetCTestConfiguration("BuildName") - << "\"\n\tBuildStamp=\"" << this->CurrentTag << "-" - << this->GetTestModelString() << "\"\n\tName=\"" - << this->GetCTestConfiguration("Site") << "\"\n\tGenerator=\"ctest-" - << cmVersion::GetCMakeVersion() << "\"\n" + << "GetCTestConfiguration("Compiler") + << "\tCompilerName=\"" << this->GetCTestConfiguration("Compiler") << "\"\n" #ifdef _COMPILER_VERSION << "\tCompilerVersion=\"_COMPILER_VERSION\"\n" diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 44a534907..7c71b00ea 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -259,6 +259,10 @@ public: std::string* stdOut, std::string* stdErr, int* retVal = 0, const char* dir = 0, double timeout = 0.0); + //! Clean/make safe for xml the given value such that it may be used as + // one of the key fields by CDash when computing the buildid. + static std::string SafeBuildIdField(const std::string& value); + //! Start CTest XML output file void StartXML(std::ostream& ostr, bool append);