GenEx: Validate target and property names.
They must be non-empty, and match a restrictive regexp.
This commit is contained in:
parent
b3d8f5dab7
commit
8b3b88abd8
|
@ -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,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:Invali/dTarget,INCLUDE_DIRECTORIES>
|
||||
|
||||
Target name not supported.
|
|
@ -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>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:Invali/dTarget,Invali/dProperty>
|
||||
|
||||
Target name and property name not supported.$
|
|
@ -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>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:Invali/dProperty>
|
||||
|
||||
Property name not supported.$
|
|
@ -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>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:foo,Invali/dProperty>
|
||||
|
||||
Property name not supported.$
|
|
@ -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>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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:,>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:,ValidProperty>
|
||||
|
||||
\$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty target name.
|
|
@ -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>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:foo,>
|
||||
|
||||
\$<TARGET_PROPERTY:...> expression requires a non-empty property name.
|
|
@ -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,>")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PROPERTY:>
|
||||
|
||||
\$<TARGET_PROPERTY:...> expression requires a non-empty property name.
|
|
@ -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:>")
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue