mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-27 10:18:10 +00:00
CPS: Fix crash when package requires isn't an object
Check whether a package `requires` is actually an object before trying to iterate over it.
This commit is contained in:
@@ -591,6 +591,9 @@ std::vector<cmPackageRequirement> cmPackageInfoReader::GetRequirements() const
|
||||
std::vector<cmPackageRequirement> requirements;
|
||||
|
||||
auto const& requirementObjects = this->Data["requires"];
|
||||
if (!requirementObjects.isObject()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
for (auto ri = requirementObjects.begin(), re = requirementObjects.end();
|
||||
ri != re; ++ri) {
|
||||
|
||||
@@ -283,6 +283,19 @@ elseif(NOT TARGET Bar::Target2)
|
||||
message(SEND_ERROR "Bar::Target2 missing !")
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Find some packages with malformatted dependencies.
|
||||
|
||||
find_package(Bad1)
|
||||
if(NOT Bad1_FOUND)
|
||||
message(SEND_ERROR "Bad1 not found !")
|
||||
endif()
|
||||
|
||||
find_package(Bad2)
|
||||
if(NOT Bad2_FOUND)
|
||||
message(SEND_ERROR "Bad2 not found !")
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Test requesting components from a package.
|
||||
|
||||
|
||||
11
Tests/FindPackageCpsTest/cps/bad1.cps
Normal file
11
Tests/FindPackageCpsTest/cps/bad1.cps
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "Bad1",
|
||||
"cps_path": "@prefix@/cps",
|
||||
"requires": "Broken",
|
||||
"components": {
|
||||
"Target": {
|
||||
"type": "interface"
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Tests/FindPackageCpsTest/cps/bad2.cps
Normal file
11
Tests/FindPackageCpsTest/cps/bad2.cps
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "Bad2",
|
||||
"cps_path": "@prefix@/cps",
|
||||
"requires": [ "Broken" ],
|
||||
"components": {
|
||||
"Target": {
|
||||
"type": "interface"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user