Bug 1423855 - Quit if the profile path is not valid UTF-8 on non-Windows platforms. draft
authorHenri Sivonen <hsivonen@hsivonen.fi>
Thu, 07 Dec 2017 12:18:47 +0200
changeset 709561 54128ed634ae889704330690017ca60d0632436d
parent 709513 abdb267c33222b55729bd52a022f226c60af6201
child 743458 d14973ef8e21570993d3efd9e7eeaa15ac4be71c
push id92690
push userbmo:hsivonen@hsivonen.fi
push dateFri, 08 Dec 2017 09:14:19 +0000
bugs1423855
milestone59.0a1
Bug 1423855 - Quit if the profile path is not valid UTF-8 on non-Windows platforms. On non-Windows platforms Firefox is broken in various ways (unable to save history and bookmarks, for example) if the profile path isn't valid UTF-8. It's better to check that up front instead of being broken in mysterious ways. MozReview-Commit-ID: 76XxIB3cuvh
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -15,16 +15,17 @@
 #include "mozilla/MemoryChecking.h"
 #include "mozilla/Poison.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Printf.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Services.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/intl/LocaleService.h"
+#include "nsNativeCharsetUtils.h"
 
 #include "nsAppRunner.h"
 #include "mozilla/XREAppData.h"
 #include "mozilla/Bootstrap.h"
 #if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
 #include "nsUpdateDriver.h"
 #endif
 #include "ProfileReset.h"
@@ -4462,16 +4463,26 @@ XREMain::XRE_mainRun()
       }
 
       // Need to write out the fact that the profile has been removed, the new profile
       // renamed, and potentially that the selected/default profile changed.
       mProfileSvc->Flush();
     }
   }
 
+  if (NS_IsNativeUTF8()) {
+    nsCOMPtr<nsIFile> profileDir;
+    nsAutoCString path;
+    rv = mDirProvider.GetProfileStartupDir(getter_AddRefs(profileDir));
+    if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(profileDir->GetNativePath(path)) && !IsUTF8(path)) {
+      PR_fprintf(PR_STDERR, "Error: The profile path is not valid UTF-8. Unable to continue.\n");
+      return NS_ERROR_FAILURE;
+    }
+  }
+
   // Initialize user preferences before notifying startup observers so they're
   // ready in time for early consumers, such as the component loader.
   mDirProvider.InitializeUserPrefs();
 
   {
     nsCOMPtr<nsIObserver> startupNotifier
       (do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID, &rv));
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);