Skip to content
Permalink
Browse files

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: #6828
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
thefourtheye authored and rvagg committed May 18, 2016
1 parent 5afb91b commit c068880757b4dc86156f4ea3f6c720e929351a20
Showing with 4 additions and 1 deletion.
  1. +2 −1 lib/fs.js
  2. +2 −0 test/parallel/test-fs-mkdtemp.js
@@ -1994,7 +1994,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');

@@ -25,3 +25,5 @@ fs.mkdtemp(
assert(common.fileExists(folder));
})
);

assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));

0 comments on commit c068880

Please sign in to comment.
You can’t perform that action at this time.