Skip to content

Commit 8bf79b4

Browse files
committed
lib: Prevent leaking arguments in several places.
1 parent 214d020 commit 8bf79b4

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

lib/console.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const util = require('util');
4+
const assert = require('assert');
45

56
function Console(stdout, stderr) {
67
if (!(this instanceof Console)) {
@@ -83,8 +84,11 @@ Console.prototype.trace = function trace() {
8384

8485
Console.prototype.assert = function(expression) {
8586
if (!expression) {
86-
var arr = Array.prototype.slice.call(arguments, 1);
87-
require('assert').ok(false, util.format.apply(this, arr));
87+
var argsleft = arguments.length - 1;
88+
const arr = new Array(argsleft > 0 ? argsleft : 0);
89+
while (argsleft-- > 0) arr[argsleft] = arguments[argsleft + 1];
90+
91+
assert.ok(false, util.format.apply(this, arr));
8892
}
8993
};
9094

lib/path.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,13 @@ win32.isAbsolute = function(path) {
185185
};
186186

187187
win32.join = function() {
188-
function f(p) {
189-
if (typeof p !== 'string') {
190-
throw new TypeError('Arguments to path.join must be strings');
191-
}
192-
return p;
188+
const paths = new Array(arguments.length);
189+
for (var i = 0; i < arguments.length; i++) {
190+
if (typeof arguments[i] !== 'string') {
191+
throw new TypeError('Arguments to path.join must be strings');
192+
}
193+
paths[i] = arguments[i];
193194
}
194-
195-
var paths = Array.prototype.filter.call(arguments, f);
196195
var joined = paths.join('\\');
197196

198197
// Make sure that the joined path doesn't start with two slashes, because

lib/util.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ exports.format = function(f) {
1515

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

18+
var argsleft = arguments.length;
19+
const args = new Array(argsleft);
20+
while (argsleft--) args[argsleft] = arguments[argsleft];
21+
1822
var i = 1;
19-
var args = arguments;
2023
var len = args.length;
2124
var str = String(f).replace(formatRegExp, function(x) {
2225
if (x === '%%') return '%';

0 commit comments

Comments
 (0)