Bug 973538 - Throw an exception on undefined values for OS.Path.join() and OS.Path.winGetDrive(). r=Yoric
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Mon, 17 Feb 2014 12:02:26 +0100
changeset 189998 170b1052afc5bcb8a02cdc9fc3f49aaa671866e1
parent 189997 80ea77dd1eac3ee9d4118e104630d0a2c6156a02
child 189999 086c209d637f6d19d30ee3ff5f75613db99fde47
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs973538
milestone30.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 973538 - Throw an exception on undefined values for OS.Path.join() and OS.Path.winGetDrive(). r=Yoric
toolkit/components/osfile/modules/ospath_unix.jsm
toolkit/components/osfile/modules/ospath_win.jsm
--- a/toolkit/components/osfile/modules/ospath_unix.jsm
+++ b/toolkit/components/osfile/modules/ospath_unix.jsm
@@ -74,24 +74,27 @@ exports.dirname = dirname;
  * in a directory.
  *
  * Example: Obtaining $TMP/foo/bar in an OS-independent manner
  *  var tmpDir = OS.Constants.Path.tmpDir;
  *  var path = OS.Path.join(tmpDir, "foo", "bar");
  *
  * Under Unix, this will return "/tmp/foo/bar".
  */
-let join = function(path /*...*/) {
+let join = function(...path) {
   // If there is a path that starts with a "/", eliminate everything before
   let paths = [];
-  for each(let i in arguments) {
-    if (i.length != 0 && i[0] == "/") {
-      paths = [i];
+  for (let subpath of path) {
+    if (subpath == null) {
+      throw new TypeError("invalid path component");
+    }
+    if (subpath.length != 0 && subpath[0] == "/") {
+      paths = [subpath];
     } else {
-      paths.push(i);
+      paths.push(subpath);
     }
   }
   return paths.join("/");
 };
 exports.join = join;
 
 /**
  * Normalize a path by removing any unneeded ".", "..", "//".
--- a/toolkit/components/osfile/modules/ospath_win.jsm
+++ b/toolkit/components/osfile/modules/ospath_win.jsm
@@ -135,17 +135,20 @@ exports.dirname = dirname;
  *  var path = OS.Path.join(tmpDir, "foo", "bar");
  *
  * Under Windows, this will return "$TMP\foo\bar".
  */
 let join = function(...path) {
   let paths = [];
   let root;
   let absolute = false;
-  for each(let subpath in path) {
+  for (let subpath of path) {
+    if (subpath == null) {
+      throw new TypeError("invalid path component");
+    }
     let drive = this.winGetDrive(subpath);
     if (drive) {
       root = drive;
       let component = trimBackslashes(subpath.slice(drive.length));
       if (component) {
         paths = [component];
       } else {
         paths = [];
@@ -174,16 +177,20 @@ exports.join = join;
  * Return the drive name of a path, or |null| if the path does
  * not contain a drive name.
  *
  * Drive name appear either as "DriveName:..." (the return drive
  * name includes the ":") or "\\\\DriveName..." (the returned drive name
  * includes "\\\\").
  */
 let winGetDrive = function(path) {
+  if (path == null) {
+    throw new TypeError("path is invalid");
+  }
+
   if (path.startsWith("\\\\")) {
     // UNC path
     if (path.length == 2) {
       return null;
     }
     let index = path.indexOf("\\", 2);
     if (index == -1) {
       return path;