[PATCH] D18011: [modules] Diagnose insufficient privileges when trying to load the modulemap

Davide Italiano via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 9 12:40:09 PST 2016


davide updated this revision to Diff 50181.
davide added a comment.

Typo.


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 module 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18011.50181.patch
Type: text/x-patch
Size: 1730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160309/7a73c434/attachment.bin>


More information about the cfe-commits mailing list