fs: mkdtemp shouldn't crash if no callback passed

As it is, `fs.mkdtemp` crashes with a C++ assertion if the callback
function is not passed. This patch uses `maybeCallback` to create one,
if no callback function is passed.

PR-URL: https://github.com/nodejs/node/pull/6828
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Sakthipriyan Vairamani 2016-05-18 17:22:17 +05:30 committed by James M Snell
parent 2ef83590ce
commit dcbf246b35
2 changed files with 4 additions and 1 deletions

View File

@ -2000,7 +2000,8 @@ SyncWriteStream.prototype.destroy = function() {
SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy;
fs.mkdtemp = function(prefix, options, callback) {
fs.mkdtemp = function(prefix, options, callback_) {
var callback = maybeCallback(callback_);
if (!prefix || typeof prefix !== 'string')
throw new TypeError('filename prefix is required');

View File

@ -25,3 +25,5 @@ fs.mkdtemp(
assert(common.fileExists(folder));
})
);
assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));