Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Prevent leaking arguments in several places. #1752

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: Prevent leaking arguments in several places.
  • Loading branch information
ChALkeR committed May 24, 2015
commit 8bf79b42841687ad1bf0710eb945c10b4313a8b9
8 changes: 6 additions & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('util');
const assert = require('assert');

function Console(stdout, stderr) {
if (!(this instanceof Console)) {
Expand Down Expand Up @@ -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));
}
};

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;
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
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 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 '%';
Expand Down