Sfoglia il codice sorgente

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
Joerg Bornemann 3 mesi fa
parent
commit
2c300a4c0a
1 ha cambiato i file con 4 aggiunte e 4 eliminazioni
  1. 4 4
      Source/cmDependsCompiler.cxx

+ 4 - 4
Source/cmDependsCompiler.cxx

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