Skip to content

Commit

Permalink
fs: mkdtemp shouldn't crash if no callback passed
Browse files Browse the repository at this point in the history
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 Jun 2, 2016
1 parent 5afb91b commit c068880
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-fs-mkdtemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.