[clang] [clang-installapi] ] Fix potential null pointer dereference in file enumeration (PR #97900)

Cyndy Ishida via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 08:46:27 PDT 2024


================
@@ -51,8 +51,14 @@ llvm::Expected<PathSeq> enumerateFiles(FileManager &FM, StringRef Directory) {
     if (EC)
       return errorCodeToError(EC);
 
+    // Ensure the iterator is valid before dereferencing.
+    if (i == ie)
+      break;
+
     // Skip files that do not exist. This usually happens for broken symlinks.
-    if (FS.status(i->path()) == std::errc::no_such_file_or_directory)
+    auto StatusOrErr = FS.status(i->path());
+    if (!StatusOrErr ||
----------------
cyndyishida wrote:

I'm not sure about this either. Where is the possible null pointer access? I also think `!StatusOrErr` is now too strict that we'd skip over other paths that may have other errors that we may want to still store. 

https://github.com/llvm/llvm-project/pull/97900


More information about the cfe-commits mailing list