[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:39:11 PST 2016


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;


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


More information about the cfe-commits mailing list