-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
@@ -594,28 +594,49 @@ fn op_open( | |||
open_options.read(true); | |||
} | |||
"r+" => { | |||
if let Err(e) = state.check_write(&filename_str) { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe...
There was a problem hiding this comment.
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
}
There was a problem hiding this 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.
- 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)
Currently,
deno.open
does not do any write permission checks...This PR adds such checks.