From 8b3b88abd82a36daf541dfa7094f978e0be08efc Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Oct 2012 00:31:24 +0200 Subject: GenEx: Validate target and property names. They must be non-empty, and match a restrictive regexp. --- Source/cmGeneratorExpressionEvaluator.cxx | 47 +++++++++++++++++++++- .../BadInvalidName1-result.txt | 1 + .../BadInvalidName1-stderr.txt | 6 +++ .../BadInvalidName1.cmake | 7 ++++ .../BadInvalidName2-result.txt | 1 + .../BadInvalidName2-stderr.txt | 6 +++ .../BadInvalidName2.cmake | 7 ++++ .../BadInvalidName3-result.txt | 1 + .../BadInvalidName3-stderr.txt | 6 +++ .../BadInvalidName3.cmake | 7 ++++ .../BadInvalidName4-result.txt | 1 + .../BadInvalidName4-stderr.txt | 6 +++ .../BadInvalidName4.cmake | 9 +++++ .../BadInvalidName5-result.txt | 1 + .../BadInvalidName5-stderr.txt | 7 ++++ .../BadInvalidName5.cmake | 7 ++++ .../BadInvalidName6-result.txt | 1 + .../BadInvalidName6-stderr.txt | 6 +++ .../BadInvalidName6.cmake | 7 ++++ .../BadInvalidName7-result.txt | 1 + .../BadInvalidName7-stderr.txt | 6 +++ .../BadInvalidName7.cmake | 9 +++++ .../BadInvalidName8-result.txt | 1 + .../BadInvalidName8-stderr.txt | 6 +++ .../BadInvalidName8.cmake | 7 ++++ .../RunCMakeTest.cmake | 8 ++++ 26 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 80cffe9..12809f4 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -274,11 +274,42 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode "$ expression requires one or two parameters"); return std::string(); } + cmsys::RegularExpression nameValidator; + nameValidator.compile("^[A-Za-z0-9_.-]+$"); + cmGeneratorTarget* target = context->Target; std::string propertyName = *parameters.begin(); if (parameters.size() == 2) { + if (parameters.begin()->empty() && parameters.at(1).empty()) + { + reportError(context, content->GetOriginalExpression(), + "$ expression requires a non-empty " + "target name and property name."); + return std::string(); + } + if (parameters.begin()->empty()) + { + reportError(context, content->GetOriginalExpression(), + "$ expression requires a non-empty " + "target name."); + return std::string(); + } + std::string targetName = parameters.front(); + propertyName = parameters.at(1); + if (!nameValidator.find(targetName.c_str())) + { + if (!nameValidator.find(propertyName.c_str())) + { + ::reportError(context, content->GetOriginalExpression(), + "Target name and property name not supported."); + return std::string(); + } + ::reportError(context, content->GetOriginalExpression(), + "Target name not supported."); + return std::string(); + } target = context->Makefile->FindGeneratorTargetToUse( targetName.c_str()); @@ -291,7 +322,21 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode reportError(context, content->GetOriginalExpression(), e.str()); return std::string(); } - propertyName = parameters.at(1); + } + + if (propertyName.empty()) + { + reportError(context, content->GetOriginalExpression(), + "$ expression requires a non-empty property " + "name."); + return std::string(); + } + + if (!nameValidator.find(propertyName.c_str())) + { + ::reportError(context, content->GetOriginalExpression(), + "Property name not supported."); + return std::string(); } cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt new file mode 100644 index 0000000..3287d19 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Target name not supported. diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake new file mode 100644 index 0000000..d5f661d --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName1.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt new file mode 100644 index 0000000..e527e22 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Target name and property name not supported.$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake new file mode 100644 index 0000000..6e4c1d0 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName2.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt new file mode 100644 index 0000000..517debb --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Property name not supported.$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake new file mode 100644 index 0000000..3f75aa3 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName3.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt new file mode 100644 index 0000000..eab6fb6 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Property name not supported.$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake new file mode 100644 index 0000000..b616c31 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName4.cmake @@ -0,0 +1,9 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(foo "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt new file mode 100644 index 0000000..e2b4fc6 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5-stderr.txt @@ -0,0 +1,7 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + \$ expression requires a non-empty target name and + property name. diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake new file mode 100644 index 0000000..11cb6fa --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName5.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt new file mode 100644 index 0000000..e94f52f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + \$ expression requires a non-empty target name. diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake new file mode 100644 index 0000000..bf868a5 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName6.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt new file mode 100644 index 0000000..2548215 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + \$ expression requires a non-empty property name. diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake new file mode 100644 index 0000000..36d1a79 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName7.cmake @@ -0,0 +1,9 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(foo "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt new file mode 100644 index 0000000..2a98f6f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + \$ expression requires a non-empty property name. diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake new file mode 100644 index 0000000..f059288 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadInvalidName8.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake index e2abd56..0ee3238 100644 --- a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake @@ -7,3 +7,11 @@ run_cmake(BadSelfReference4) run_cmake(BadSelfReference5) run_cmake(BadSelfReference6) run_cmake(BadNonTarget) +run_cmake(BadInvalidName1) +run_cmake(BadInvalidName2) +run_cmake(BadInvalidName3) +run_cmake(BadInvalidName4) +run_cmake(BadInvalidName5) +run_cmake(BadInvalidName6) +run_cmake(BadInvalidName7) +run_cmake(BadInvalidName8) -- cgit v0.12