Bug 1434666 - Avoid path aliasing in AppendToLibPath r=rstrong
authorArthur Edelstein <arthuredelstein@gmail.com>
Mon, 12 Feb 2018 21:46:00 +0200
changeset 404080 855eb2e4c43d209acd2addb0c598fb9a7603c058
parent 404079 fa3a632406656d0676d1065e33fe1dd09aaf5ee0
child 404081 e6fc425cf9b479597aacc8646b1d21b2c529e299
push id33451
push usernbeleuzu@mozilla.com
push dateFri, 16 Feb 2018 09:51:13 +0000
treeherdermozilla-central@9eaebbcc33fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1434666
milestone60.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 1434666 - Avoid path aliasing in AppendToLibPath r=rstrong Previously, it was possible for AppendToLibPath to fail to add the directory /A/B/C/ to LD_LIBRARY_PATH if the directory /A/B/C/D/ was already present.
toolkit/xre/nsUpdateDriver.cpp
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -377,21 +377,28 @@ CopyUpdaterIntoUpdateDir(nsIFile *greDir
 static void
 AppendToLibPath(const char *pathToAppend)
 {
   char *pathValue = getenv(LD_LIBRARY_PATH_ENVVAR_NAME);
   if (nullptr == pathValue || '\0' == *pathValue) {
     // Leak the string because that is required by PR_SetEnv.
     char *s = Smprintf("%s=%s", LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend).release();
     PR_SetEnv(s);
-  } else if (!strstr(pathValue, pathToAppend)) {
-    // Leak the string because that is required by PR_SetEnv.
-    char *s = Smprintf("%s=%s" PATH_SEPARATOR "%s",
-                       LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend, pathValue).release();
-    PR_SetEnv(s);
+  } else {
+    // Check if pathToAppend is present in pathValue, properly delimited.
+    // For example, if pathValue = "/A/B/C/D" and pathToAppend = "/A/B/C"
+    // then check if ":/A/B/C/D:" contains ":/A/B/C:" (answer: no).
+    char *pathValue_sep = Smprintf(PATH_SEPARATOR "%s" PATH_SEPARATOR, pathValue).get();
+    char *pathToAppend_sep = Smprintf(PATH_SEPARATOR "%s" PATH_SEPARATOR, pathToAppend).get();
+    if (!strstr(pathValue_sep, pathToAppend_sep)) {
+      // Leak the string because that is required by PR_SetEnv.
+      char *s = Smprintf("%s=%s" PATH_SEPARATOR "%s",
+                         LD_LIBRARY_PATH_ENVVAR_NAME, pathToAppend, pathValue).release();
+      PR_SetEnv(s);
+    }
   }
 }
 #endif
 
 /**
  * Applies, switches, or stages an update.
  *
  * @param greDir       the GRE directory