Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upModify Post read_file to check if file is readable #11342
Conversation
bcoles
added
library
enhancement
labels
Feb 1, 2019
busterb
self-assigned this
Feb 7, 2019
This comment has been minimized.
This comment has been minimized.
This does improve things, even if there's a window for a file to be deleted. Seems to be about the best you can do on a shell session. |
busterb
merged commit 47a13ea
into
rapid7:master
Feb 7, 2019
added a commit
that referenced
this pull request
Feb 7, 2019
This comment has been minimized.
This comment has been minimized.
Release NotesThis adds a run-time check if a file exists in a shell session before trying to read that file, eliminating some types of errors. |
bcoles
deleted the
bcoles:lib-post-file-readable
branch
Feb 7, 2019
added a commit
that referenced
this pull request
Feb 7, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
bcoles commentedFeb 1, 2019
This changes the behavior for Post
read_file
on command shell sessions to first check if a file is readable before attempting read.This fixes #9854 by ensuring that
nil
is returned in the event a file is not readable.Prior to this PR, invoking
read_file
on a command shell session, for a file which was not readable (didn't exist or insufficient permissions) would sometimes return an error message from the system (which could vary in value based on system locale) depending on whetherstderr
was routed over the socket.Advantages
It ensures consistency.
read_file
on command shell sessions will now always returnnil
if the file cannot be read, regardless of session type or remote system environment.It should be stealthier in logs, in that it won't trigger permission denied errors.
Disadvantages
It adds an extra
cmd_exec
call for every file read, and requirestest
to be in$PATH
.TOCTOU. If this is a concern, instead of executing the
test
in a separatecmd_exec
call,test -r /path/to/file &&
could be prepended in a singlecmd_exec
call.Command Shell Session
Test Code