Bug 1189352: Fix NSPR_LOG_FILE with absolute paths for sandboxed child on Windows. r=bbondy
authorBob Owen <bobowencode@gmail.com>
Mon, 03 Aug 2015 07:58:43 +0100
changeset 287475 2bf9ce6c8403454172e5211c84da133c495e0e7b
parent 287474 00e3222ed96f6a2d3c063a38caf1e9e4ba329c03
child 287476 976ba676a65900bb7ec13b657a3655d4a54bc11f
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs1189352
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1189352: Fix NSPR_LOG_FILE with absolute paths for sandboxed child on Windows. r=bbondy
ipc/glue/GeckoChildProcessHost.cpp
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -559,36 +559,37 @@ AddAppDirToCommandLine(std::vector<std::
 static void
 MaybeAddNsprLogFileAccess(std::vector<std::wstring>& aAllowedFilesReadWrite)
 {
   const char* nsprLogFileEnv = PR_GetEnv("NSPR_LOG_FILE");
   if (!nsprLogFileEnv) {
     return;
   }
 
-  nsCOMPtr<nsIFile> file;
-  nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR,
-                                       getter_AddRefs(file));
-  if (NS_FAILED(rv) || !file) {
-    NS_WARNING("Failed to get current working directory");
-    return;
-  }
+  nsDependentCString nsprLogFilePath(nsprLogFileEnv);
+  nsCOMPtr<nsIFile> nsprLogFile;
+  nsresult rv = NS_NewNativeLocalFile(nsprLogFilePath, true,
+                                      getter_AddRefs(nsprLogFile));
+  if (NS_FAILED(rv)) {
+    // Not an absolute path, try it as a relative one.
+    nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR,
+                                         getter_AddRefs(nsprLogFile));
+    if (NS_FAILED(rv) || !nsprLogFile) {
+      NS_WARNING("Failed to get current working directory");
+      return;
+    }
 
-  nsDependentCString nsprLogFile(nsprLogFileEnv);
-  rv = file->AppendRelativeNativePath(nsprLogFile);
-  if (NS_FAILED(rv)) {
-    // Not a relative path, try it as an absolute one.
-    rv = file->InitWithNativePath(nsprLogFile);
+    rv = nsprLogFile->AppendRelativeNativePath(nsprLogFilePath);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return;
     }
   }
 
   nsAutoString resolvedFilePath;
-  rv = file->GetPath(resolvedFilePath);
+  rv = nsprLogFile->GetPath(resolvedFilePath);
   if (NS_WARN_IF(NS_FAILED(rv))) {
       return;
   }
 
   // Update the environment variable as well as adding the rule, because the
   // Chromium sandbox can only allow access to fully qualified file paths. This
   // only affects the environment for the child process we're about to create,
   // because this will get reset to the original value in PerformAsyncLaunch.