mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Fix out-of-bounds read on empty gcc-style depfile
If a gcc dep file is read that contains no dependencies, cmReadGccDepfile returns a valid std::optional containing an empty vector. Check at the call sites in cmDependsCompiler whether the vector is empty before trying to access the vector's elements. Fixes: #27270
This commit is contained in:

committed by
Brad King

parent
051b0efd7d
commit
2c300a4c0a
@@ -96,9 +96,9 @@ bool cmDependsCompiler::CheckDependencies(
|
|||||||
|
|
||||||
std::vector<std::string> depends;
|
std::vector<std::string> depends;
|
||||||
if (format == "custom"_s) {
|
if (format == "custom"_s) {
|
||||||
auto deps = cmReadGccDepfile(
|
cm::optional<cmGccDepfileContent> deps = cmReadGccDepfile(
|
||||||
depFile.c_str(), this->LocalGenerator->GetCurrentBinaryDirectory());
|
depFile.c_str(), this->LocalGenerator->GetCurrentBinaryDirectory());
|
||||||
if (!deps) {
|
if (!deps || deps->empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +130,10 @@ bool cmDependsCompiler::CheckDependencies(
|
|||||||
depends.emplace_back(std::move(line));
|
depends.emplace_back(std::move(line));
|
||||||
}
|
}
|
||||||
} else if (format == "gcc"_s) {
|
} else if (format == "gcc"_s) {
|
||||||
auto deps = cmReadGccDepfile(
|
cm::optional<cmGccDepfileContent> deps = cmReadGccDepfile(
|
||||||
depFile.c_str(), this->LocalGenerator->GetCurrentBinaryDirectory(),
|
depFile.c_str(), this->LocalGenerator->GetCurrentBinaryDirectory(),
|
||||||
GccDepfilePrependPaths::Deps);
|
GccDepfilePrependPaths::Deps);
|
||||||
if (!deps) {
|
if (!deps || deps->empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user