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

fs: ensure nullCheck() callback is a function #887

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
8 changes: 4 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function nullCheck(path, callback) {
if (('' + path).indexOf('\u0000') !== -1) {
var er = new Error('Path must be a string without null bytes.');
er.code = 'ENOENT';
if (!callback)
if (typeof callback !== 'function')
throw er;
process.nextTick(function() {
callback(er);
Expand Down Expand Up @@ -169,16 +169,16 @@ fs.Stats.prototype.isSocket = function() {
});

fs.access = function(path, mode, callback) {
if (!nullCheck(path, callback))
return;

if (typeof mode === 'function') {
callback = mode;
mode = fs.F_OK;
} else if (typeof callback !== 'function') {
throw new TypeError('callback must be a function');
}

if (!nullCheck(path, callback))
return;

mode = mode | 0;
var req = new FSReqWrap();
req.oncomplete = makeCallback(callback);
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ assert.throws(function() {
fs.access(__filename, fs.F_OK);
}, /callback must be a function/);

assert.throws(function() {
fs.access(__filename, fs.F_OK, {});
}, /callback must be a function/);

assert.doesNotThrow(function() {
fs.accessSync(__filename);
});
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-fs-null-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function check(async, sync) {
async.apply(null, argsAsync);
}

check(fs.access, fs.accessSync, 'foo\u0000bar');
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);
check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar');
check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644');
check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34);
Expand Down Expand Up @@ -52,4 +54,3 @@ fs.exists('foo\u0000bar', function(exists) {
assert(!exists);
});
assert(!fs.existsSync('foo\u0000bar'));