From 8bf79b42841687ad1bf0710eb945c10b4313a8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 21 May 2015 01:24:15 +0300 Subject: [PATCH] lib: Prevent leaking arguments in several places. --- lib/console.js | 8 ++++++-- lib/path.js | 13 ++++++------- lib/util.js | 5 ++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/console.js b/lib/console.js index f9032e24a0fa44..959e17b228abd5 100644 --- a/lib/console.js +++ b/lib/console.js @@ -1,6 +1,7 @@ 'use strict'; const util = require('util'); +const assert = require('assert'); function Console(stdout, stderr) { if (!(this instanceof Console)) { @@ -83,8 +84,11 @@ Console.prototype.trace = function trace() { Console.prototype.assert = function(expression) { if (!expression) { - var arr = Array.prototype.slice.call(arguments, 1); - require('assert').ok(false, util.format.apply(this, arr)); + var argsleft = arguments.length - 1; + const arr = new Array(argsleft > 0 ? argsleft : 0); + while (argsleft-- > 0) arr[argsleft] = arguments[argsleft + 1]; + + assert.ok(false, util.format.apply(this, arr)); } }; diff --git a/lib/path.js b/lib/path.js index b7e28b22250791..88c73e4e04c9c4 100644 --- a/lib/path.js +++ b/lib/path.js @@ -185,14 +185,13 @@ win32.isAbsolute = function(path) { }; win32.join = function() { - function f(p) { - if (typeof p !== 'string') { - throw new TypeError('Arguments to path.join must be strings'); - } - return p; + const paths = new Array(arguments.length); + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); + } + paths[i] = arguments[i]; } - - var paths = Array.prototype.filter.call(arguments, f); var joined = paths.join('\\'); // Make sure that the joined path doesn't start with two slashes, because diff --git a/lib/util.js b/lib/util.js index 401d55bbe82926..0634402dea95fe 100644 --- a/lib/util.js +++ b/lib/util.js @@ -15,8 +15,11 @@ exports.format = function(f) { if (arguments.length === 1) return f; + var argsleft = arguments.length; + const args = new Array(argsleft); + while (argsleft--) args[argsleft] = arguments[argsleft]; + var i = 1; - var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function(x) { if (x === '%%') return '%';