Skip to content

Commit

Permalink
lib: Prevent leaking arguments in several places.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed May 22, 2015
1 parent 214d020 commit dd51d5b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 4 additions & 1 deletion lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ Console.prototype.trace = function trace() {

Console.prototype.assert = function(expression) {
if (!expression) {
var arr = Array.prototype.slice.call(arguments, 1);
var al = arguments.length - 1;
var arr = new Array(al > 0 ? al : 0);
while (al-- > 0) arr[al] = arguments[al + 1];

require('assert').ok(false, util.format.apply(this, arr));
}
};
Expand Down
13 changes: 6 additions & 7 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
var 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
Expand Down
5 changes: 4 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ exports.format = function(f) {

if (arguments.length === 1) return f;

var al = arguments.length;
var args = new Array(al);
while (al--) args[al] = arguments[al];

var i = 1;
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function(x) {
if (x === '%%') return '%';
Expand Down

0 comments on commit dd51d5b

Please sign in to comment.