GenEx: Validate target and property names.

They must be non-empty, and match a restrictive regexp.
This commit is contained in:
Stephen Kelly 2012-10-04 00:31:24 +02:00 committed by Brad King
parent b3d8f5dab7
commit 8b3b88abd8
26 changed files with 171 additions and 1 deletions

View File

@ -274,11 +274,42 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
"$<TARGET_PROPERTY:...> 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(),
"$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
"target name and property name.");
return std::string();
}
if (parameters.begin()->empty())
{
reportError(context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:tgt,prop> 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(),
"$<TARGET_PROPERTY:...> 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,

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>
Target name not supported.

View File

@ -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("$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>
Target name and property name not supported.$

View File

@ -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("$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:Invali/dProperty>
Property name not supported.$

View File

@ -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("$<TARGET_PROPERTY:Invali/dProperty>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:foo,Invali/dProperty>
Property name not supported.$

View File

@ -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("$<TARGET_PROPERTY:foo,Invali/dProperty>")

View File

@ -0,0 +1,7 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:,>
\$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name and
property name.

View File

@ -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("$<TARGET_PROPERTY:,>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:,ValidProperty>
\$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name.

View File

@ -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("$<TARGET_PROPERTY:,ValidProperty>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:foo,>
\$<TARGET_PROPERTY:...> expression requires a non-empty property name.

View File

@ -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("$<TARGET_PROPERTY:foo,>")

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:>
\$<TARGET_PROPERTY:...> expression requires a non-empty property name.

View File

@ -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("$<TARGET_PROPERTY:>")

View File

@ -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)