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

Fix deno.open permission check #1336

Merged
merged 1 commit into from
Dec 13, 2018
Merged

Conversation

kevinkassimo
Copy link
Contributor

Currently, deno.open does not do any write permission checks...
This PR adds such checks.

@@ -594,28 +594,49 @@ fn op_open(
open_options.read(true);
}
"r+" => {
if let Err(e) = state.check_write(&filename_str) {
Copy link
Contributor

@F001 F001 Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are repeative. What about combining them together?

// add this before the `match mode`
match mode {
"r+" | "w" | "w+" | "a" | "a+" | "x" | "x+" => {
    if let Err(e) = state.check_write(&filename_str) {
        return odd_future(e);
      }
 }
 _ => {}
}
// original code
match mode {
// set open_options
}

Copy link
Contributor Author

@kevinkassimo kevinkassimo Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does this slightly add some overhead by doing 2 separate matchings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the r mode the only one that does not need write permission? What about

// original code
match mode {
}
if mode != "r" { // mode is guaranteed to be valid
  // only need to write check_write() once
} 

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks.

I think @F001's comment about cleaning up the matches is valid - but let's do it in a follow up commit.

@ry ry merged commit 2cb52cc into denoland:master Dec 13, 2018
ry added a commit to ry/deno that referenced this pull request Dec 14, 2018
- console.assert should not throw error (denoland#1335)
- Support more modes in deno.open (denoland#1282, denoland#1336)
- Simplify code fetch logic (denoland#1322)
- readDir entry mode (denoland#1326)
- Use stderr for exceptions (denoland#1303)
- console.log formatting improvements (denoland#1327, denoland#1299)
- Expose TooLarge error code for buffers (denoland#1298)
@ry ry mentioned this pull request Dec 14, 2018
ry added a commit that referenced this pull request Dec 14, 2018
- console.assert should not throw error (#1335)
- Support more modes in deno.open (#1282, #1336)
- Simplify code fetch logic (#1322)
- readDir entry mode (#1326)
- Use stderr for exceptions (#1303)
- console.log formatting improvements (#1327, #1299)
- Expose TooLarge error code for buffers (#1298)
@kevinkassimo kevinkassimo deleted the fix/open_perm branch December 27, 2019 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants