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: add validation for fd and path #35187

Open
wants to merge 3 commits into
base: master
from

Conversation

@dylanelliott27
Copy link

@dylanelliott27 dylanelliott27 commented Sep 14, 2020

Adding validation to options fd & path in createWriteStream and createReadStream.

Fixes: #35178

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
// If fd has been set, validate, otherwise validate path.
if (this.fd !== null) {
validateInteger(this.fd, 'fd', 0);
} else if (this.fd === null) {

This comment has been minimized.

@mscdex

mscdex Sep 14, 2020
Contributor

Suggested change
} else if (this.fd === null) {
} else {
// If fd has been set, validate, otherwise validate path.
if (this.fd !== null) {
validateInteger(this.fd, 'fd', 0);
} else if (this.fd === null) {

This comment has been minimized.

@mscdex

mscdex Sep 14, 2020
Contributor

Suggested change
} else if (this.fd === null) {
} else {

assert.throws(
() => {
fs.createReadStream(null, { fd: fd });

This comment has been minimized.

@mscdex

mscdex Sep 14, 2020
Contributor

Suggested change
fs.createReadStream(null, { fd: fd });
fs.createReadStream(null, { fd });

assert.throws(
() => {
fs.createWriteStream(null, { fd: fd });

This comment has been minimized.

@mscdex

mscdex Sep 14, 2020
Contributor

Suggested change
fs.createWriteStream(null, { fd: fd });
fs.createWriteStream(null, { fd });

This comment has been minimized.

@dylanelliott27

dylanelliott27 Sep 14, 2020
Author

Hi mscdex, thanks so much for your suggestions to improve my code. I have modified the original commit message as well as implemented the changes. I had some trouble with ESLint which unfortunately caused me to change/commit an unnecessary file. I have removed this file, and I am hoping things are in a good state right now, if not, apologies as I am still getting used to things. Let me know and I can make any changes asap.

@mscdex
Copy link
Contributor

@mscdex mscdex commented Sep 14, 2020

Refs: in the commit message should instead be Fixes: as the changes should resolve the linked issue.

@dylanelliott27 dylanelliott27 force-pushed the dylanelliott27:stream-arg-validation branch from a9b57e3 to b5eb951 Sep 14, 2020
adds type validation to options fd & opts in createWriteStream and createReadStream.

Fixes: #35178
@dylanelliott27 dylanelliott27 force-pushed the dylanelliott27:stream-arg-validation branch from b5eb951 to 3bdb8c8 Sep 14, 2020
@ronag
ronag approved these changes Sep 15, 2020
@Trott Trott added the request-ci label Sep 16, 2020
@Trott
Copy link
Member

@Trott Trott commented Sep 16, 2020

@nodejs/fs This could use another review.

@github-actions github-actions bot removed the request-ci label Sep 16, 2020
@@ -131,6 +132,13 @@ function ReadStream(path, options) {
this.pos = this.start;
}

// If fd has been set, validate, otherwise validate path.
if (this.fd !== null) {

This comment has been minimized.

@ronag

ronag Oct 1, 2020
Member

this should probably be this.fd != null, undefined is also valid?

@@ -296,6 +304,13 @@ function WriteStream(path, options) {
this.closed = false;
this[kIsPerformingIO] = false;

// If fd has been set, validate, otherwise validate path.
if (this.fd !== null) {

This comment has been minimized.

@ronag

ronag Oct 1, 2020
Member

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.