Skip to content

Commit c068880

Browse files
thefourtheyervagg
authored andcommitted
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>
1 parent 5afb91b commit c068880

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/fs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,8 @@ SyncWriteStream.prototype.destroy = function() {
19941994

19951995
SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy;
19961996

1997-
fs.mkdtemp = function(prefix, options, callback) {
1997+
fs.mkdtemp = function(prefix, options, callback_) {
1998+
var callback = maybeCallback(callback_);
19981999
if (!prefix || typeof prefix !== 'string')
19992000
throw new TypeError('filename prefix is required');
20002001

test/parallel/test-fs-mkdtemp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ fs.mkdtemp(
2525
assert(common.fileExists(folder));
2626
})
2727
);
28+
29+
assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));

0 commit comments

Comments
 (0)