davide created this revision.
davide added reviewers: rsmith, silvas, doug.gregor.
davide added a subscriber: cfe-commits.

I stumbled upon this yesterday. Without this patch in palce, the module map 
load is silently ignored, and this might cause subtle breakages.

http://reviews.llvm.org/D18011

Files:
  include/clang/Basic/DiagnosticFrontendKinds.td
  lib/Frontend/FrontendActions.cpp
  test/Modules/Inputs/insufficient-privileges.modulemap

Index: lib/Frontend/FrontendActions.cpp
===================================================================
--- lib/Frontend/FrontendActions.cpp
+++ lib/Frontend/FrontendActions.cpp
@@ -272,7 +272,23 @@
       << Filename;
     return false;
   }
-  
+
+  // Emit a diagnostic if we can't read the source map.
+  vfs::Status Result;
+  bool S = CI.getFileManager().getNoncachedStatValue(Filename, Result);
+  if (!S) {
+    llvm::sys::fs::perms P = Result.getPermissions();
+    if (!(P & llvm::sys::fs::perms::all_read)) {
+      CI.getDiagnostics().Report(diag::err_module_map_wrong_perms)
+        << Filename;
+      return false;
+    }
+  } else {
+    CI.getDiagnostics().Report(diag::err_module_map_missing_stat)
+      << Filename;
+    return false;
+  }
+
   // Set up embedding for any specified files. Do this before we load any
   // source files, including the primary module map for the compilation.
   for (const auto &F : CI.getFrontendOpts().ModulesEmbedFiles) {
Index: include/clang/Basic/DiagnosticFrontendKinds.td
===================================================================
--- include/clang/Basic/DiagnosticFrontendKinds.td
+++ include/clang/Basic/DiagnosticFrontendKinds.td
@@ -179,6 +179,10 @@
   "compilation">, InGroup<DiagGroup<"module-file-config-mismatch">>, 
DefaultError;
 def err_module_map_not_found : Error<"module map file '%0' not found">, 
   DefaultFatal;
+def err_module_map_wrong_perms : Error<"insufficient privileges to read file 
'%0'">,
+  DefaultFatal;
+def err_module_map_missing_stat : Error<"cannot retrieve status infos for file 
'%0'">,
+  DefaultFatal;
 def err_missing_module_name : Error<
   "no module name provided; specify one with -fmodule-name=">, 
   DefaultFatal;


Index: lib/Frontend/FrontendActions.cpp
===================================================================
--- lib/Frontend/FrontendActions.cpp
+++ lib/Frontend/FrontendActions.cpp
@@ -272,7 +272,23 @@
       << Filename;
     return false;
   }
-  
+
+  // Emit a diagnostic if we can't read the source map.
+  vfs::Status Result;
+  bool S = CI.getFileManager().getNoncachedStatValue(Filename, Result);
+  if (!S) {
+    llvm::sys::fs::perms P = Result.getPermissions();
+    if (!(P & llvm::sys::fs::perms::all_read)) {
+      CI.getDiagnostics().Report(diag::err_module_map_wrong_perms)
+        << Filename;
+      return false;
+    }
+  } else {
+    CI.getDiagnostics().Report(diag::err_module_map_missing_stat)
+      << Filename;
+    return false;
+  }
+
   // Set up embedding for any specified files. Do this before we load any
   // source files, including the primary module map for the compilation.
   for (const auto &F : CI.getFrontendOpts().ModulesEmbedFiles) {
Index: include/clang/Basic/DiagnosticFrontendKinds.td
===================================================================
--- include/clang/Basic/DiagnosticFrontendKinds.td
+++ include/clang/Basic/DiagnosticFrontendKinds.td
@@ -179,6 +179,10 @@
   "compilation">, InGroup<DiagGroup<"module-file-config-mismatch">>, DefaultError;
 def err_module_map_not_found : Error<"module map file '%0' not found">, 
   DefaultFatal;
+def err_module_map_wrong_perms : Error<"insufficient privileges to read file '%0'">,
+  DefaultFatal;
+def err_module_map_missing_stat : Error<"cannot retrieve status infos for file '%0'">,
+  DefaultFatal;
 def err_missing_module_name : Error<
   "no module name provided; specify one with -fmodule-name=">, 
   DefaultFatal;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to