cmComputeLinkInformation: Fix out-of-bounds read in error case

In commit aba1c9d172 (target_link_libraries: Add support for the
LINKER: prefix, 2024-10-06) we added a call to `ResolveLinkerWrapper`.
Update the call site to account for the possibility of an empty result
vector on error.
This commit is contained in:
Brad King
2025-01-20 10:39:25 -05:00
parent 1d5c1b0023
commit 0fbc300bec

View File

@@ -1904,11 +1904,14 @@ void cmComputeLinkInformation::AddUserItem(LinkEntry const& entry,
this->Items.emplace_back(item, ItemIsPath::No);
return;
}
if (cmHasPrefix(item.Value, LINKER)) {
std::vector<BT<std::string>> linkerFlag{ 1, item };
this->Target->ResolveLinkerWrapper(linkerFlag, this->GetLinkLanguage(),
true);
this->Items.emplace_back(linkerFlag.front(), ItemIsPath::No);
/* joinItems = */ true);
if (!linkerFlag.empty()) {
this->Items.emplace_back(linkerFlag.front(), ItemIsPath::No);
}
return;
}