Bug 1271574 - Purposefully leak the XUL_APP_FILE string passed to putenv. r=bsmedberg, a=sylvestre
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 02 Jun 2016 08:44:16 +0900
changeset 335330 634aedddd904cf6b9004590dbc2f5491fe4474ff
parent 335329 126e28e88202c405e2f8e3bbec43f54986a61aa8
child 335331 ff2241804c184482e98b0aa349af13020c7a3b82
push id1146
push userCallek@gmail.com
push dateMon, 25 Jul 2016 16:35:44 +0000
treeherdermozilla-release@a55778f9cd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, sylvestre
bugs1271574, 552864
milestone48.0
Bug 1271574 - Purposefully leak the XUL_APP_FILE string passed to putenv. r=bsmedberg, a=sylvestre Before bug 552864, the string was created with PR_smprintf, and PR_SetEnv'ed (which, under the hood, just calls putenv). PR_smprintf was allocating the string on the heap. Now, it's allocated on the stack, and still putenv'ed. putenv kind of takes ownership of the strings it's being passed, so stack allocated strings are dangerous to use. It looks like we've been fairly lucky that it worked, presumably because compilers would keep the stack frame with the variable, but that's not guaranteed to happen, and in some case, doesn't. So we strdup the string and purposefully leak it instead, which matches what happened before bug 552864, and is the only "sane" way to use putenv.
b2g/app/B2GLoader.cpp
b2g/app/nsBrowserApp.cpp
browser/app/nsBrowserApp.cpp
--- a/b2g/app/B2GLoader.cpp
+++ b/b2g/app/B2GLoader.cpp
@@ -133,17 +133,17 @@ GetAppIni(int argc, const char *argv[])
       return nullptr;
     }
 
     rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     char appEnv[MAXPATHLEN];
     snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
-    if (putenv(appEnv)) {
+    if (putenv(strdup(appEnv))) {
       return nullptr;
     }
   }
 
   return appini.forget();
 }
 
 static bool
--- a/b2g/app/nsBrowserApp.cpp
+++ b/b2g/app/nsBrowserApp.cpp
@@ -133,17 +133,17 @@ static int do_main(int argc, char* argv[
     rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
     if (NS_FAILED(rv)) {
       Output("application.ini path not recognized: '%s'", argv[2]);
       return 255;
     }
 
     char appEnv[MAXPATHLEN];
     snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
-    if (putenv(appEnv)) {
+    if (putenv(strdup(appEnv))) {
       Output("Couldn't set %s.\n", appEnv);
       return 255;
     }
     argv[2] = argv[0];
     argv += 2;
     argc -= 2;
   }
 
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -163,17 +163,17 @@ static int do_main(int argc, char* argv[
     rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
     if (NS_FAILED(rv)) {
       Output("application.ini path not recognized: '%s'", argv[2]);
       return 255;
     }
 
     char appEnv[MAXPATHLEN];
     snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
-    if (putenv(appEnv)) {
+    if (putenv(strdup(appEnv))) {
       Output("Couldn't set %s.\n", appEnv);
       return 255;
     }
     argv[2] = argv[0];
     argv += 2;
     argc -= 2;
   } else if (argc > 1 && IsArg(argv[1], "xpcshell")) {
     for (int i = 1; i < argc; i++) {