Bug 1162327 Part 2: Add temporary code to clean up the old low integrity temps on Windows. r=jimm
authorBob Owen <bobowencode@gmail.com>
Mon, 18 May 2015 11:53:57 +0100
changeset 265181 ca9f095bb18cd0318938b7ebc634f27bba21a1dd
parent 265180 116d87a1a2a8e405fd93992dbe7aedaed82aa0f7
child 265182 294fc78e528c217fd0c7e1bd9fc1d2687b5266ba
push id2102
push usermartin.thomson@gmail.com
push dateMon, 18 May 2015 17:35:37 +0000
reviewersjimm
bugs1162327
milestone41.0a1
Bug 1162327 Part 2: Add temporary code to clean up the old low integrity temps on Windows. r=jimm
dom/ipc/ContentProcess.cpp
--- a/dom/ipc/ContentProcess.cpp
+++ b/dom/ipc/ContentProcess.cpp
@@ -59,16 +59,66 @@ SetUpSandboxEnvironment()
   // Change the gecko defined temp directory to our low integrity one.
   // Undefine returns a failure if the property is not already set.
   unused << nsDirectoryService::gService->Undefine(NS_OS_TEMP_DIR);
   rv = nsDirectoryService::gService->Set(NS_OS_TEMP_DIR, lowIntegrityTemp);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 }
+
+#if defined(NIGHTLY_BUILD)
+static void
+CleanUpOldSandboxEnvironment()
+{
+  // Temporary code to clean up the old low integrity temp directories.
+  // The removal of this is tracked by bug 1165818.
+  nsCOMPtr<nsIFile> lowIntegrityMozilla;
+  nsresult rv = NS_GetSpecialDirectory(NS_WIN_LOCAL_APPDATA_LOW_DIR,
+                              getter_AddRefs(lowIntegrityMozilla));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  rv = lowIntegrityMozilla->Append(NS_LITERAL_STRING(MOZ_USER_DIR));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  nsCOMPtr<nsISimpleEnumerator> iter;
+  rv = lowIntegrityMozilla->GetDirectoryEntries(getter_AddRefs(iter));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  bool more;
+  nsCOMPtr<nsISupports> elem;
+  while (NS_SUCCEEDED(iter->HasMoreElements(&more)) && more) {
+    rv = iter->GetNext(getter_AddRefs(elem));
+    if (NS_FAILED(rv)) {
+      break;
+    }
+
+    nsCOMPtr<nsIFile> file = do_QueryInterface(elem);
+    if (!file) {
+      continue;
+    }
+
+    nsAutoString leafName;
+    rv = file->GetLeafName(leafName);
+    if (NS_FAILED(rv)) {
+      continue;
+    }
+
+    if (leafName.Find(NS_LITERAL_STRING("MozTemp-{")) == 0) {
+      file->Remove(/* aRecursive */ true);
+    }
+  }
+}
+#endif
 #endif
 
 void
 ContentProcess::SetAppDir(const nsACString& aPath)
 {
   mXREEmbed.SetAppDir(aPath);
 }
 
@@ -86,13 +136,16 @@ ContentProcess::Init()
 #endif
     
     return true;
 }
 
 void
 ContentProcess::CleanUp()
 {
+#if defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX) && defined(NIGHTLY_BUILD)
+    CleanUpOldSandboxEnvironment();
+#endif
     mXREEmbed.Stop();
 }
 
 } // namespace dom
 } // namespace mozilla