FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fs: avoid out-of-bounds arguments index access by tjhosford · Pull Request #11115 · nodejs/node · GitHub

/ node Public
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
38 changes: 31 additions & 7 deletions lib/fs.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ fs.existsSync = function(path) {
};

fs.readFile = function(path, options, callback) {
callback = maybeCallback(arguments[arguments.length - 1]);
if (arguments.length) {
callback = maybeCallback(arguments[arguments.length - 1]);
} else {
callback = rethrow();
}
options = getOptions(options, { flag: 'r' });

if (!nullCheck(path, callback))
Expand Down Expand Up @@ -534,7 +538,13 @@ function modeNum(m, def) {
}

fs.open = function(path, flags, mode, callback_) {
var callback = makeCallback(arguments[arguments.length - 1]);
var callback;

if (arguments.length) {
callback = makeCallback(arguments[arguments.length - 1]);
} else {
callback = rethrow();
}
mode = modeNum(mode, 0o666);

if (!nullCheck(path, callback)) return;
Expand Down Expand Up @@ -857,7 +867,13 @@ function preprocessSymlinkDestination(path, type, linkPath) {

fs.symlink = function(target, path, type_, callback_) {
var type = (typeof type_ === 'string' ? type_ : null);
var callback = makeCallback(arguments[arguments.length - 1]);
var callback;

if (arguments.length) {
callback = makeCallback(arguments[arguments.length - 1]);
} else {
callback = rethrow();
}

if (!nullCheck(target, callback)) return;
if (!nullCheck(path, callback)) return;
Expand Down Expand Up @@ -1074,8 +1090,7 @@ fs.futimesSync = function(fd, atime, mtime) {
binding.futimes(fd, atime, mtime);
};

function writeAll(fd, isUserFd, buffer, offset, length, position, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
function writeAll(fd, isUserFd, buffer, offset, length, position, callback) {

// write(fd, buffer, offset, length, position, callback)
fs.write(fd, buffer, offset, length, position, function(writeErr, written) {
Expand Down Expand Up @@ -1107,7 +1122,11 @@ function writeAll(fd, isUserFd, buffer, offset, length, position, callback_) {
}

fs.writeFile = function(path, data, options, callback) {
callback = maybeCallback(arguments[arguments.length - 1]);
if (arguments.length) {
callback = maybeCallback(arguments[arguments.length - 1]);
} else {
callback = rethrow();
}
options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'w' });
const flag = options.flag || 'w';

Expand Down Expand Up @@ -1161,7 +1180,12 @@ fs.writeFileSync = function(path, data, options) {
};

fs.appendFile = function(path, data, options, callback) {
callback = maybeCallback(arguments[arguments.length - 1]);
if (arguments.length) {
callback = maybeCallback(arguments[arguments.length - 1]);
} else {
callback = rethrow();
}

options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' });

// Don't make changes directly on options object
Expand Down

Back | FazBrowse Home | New Git URL