-
Notifications
You must be signed in to change notification settings - Fork 91
check if elffile is a file, make exception more descriptive #193
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
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for your contribution, looks really good. I left a comment.
src/core/elf_file.cpp
Outdated
@@ -162,8 +162,8 @@ namespace linuxdeploy { | |||
|
|||
ElfFile::ElfFile(const boost::filesystem::path& path) { | |||
// check if file exists | |||
if (!bf::exists(path)) | |||
throw ElfFileParseError("No such file or directory: " + path.string()); | |||
if (!bf::exists(path) || !bf::is_regular_file(path)) |
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.
I think exists
is redundant, isn't it? I haven't checked the docs.
We should switch to C++17...
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.
Indeed, exists
is redundant here. Please fix.
src/core/elf_file.cpp
Outdated
@@ -162,8 +162,8 @@ namespace linuxdeploy { | |||
|
|||
ElfFile::ElfFile(const boost::filesystem::path& path) { | |||
// check if file exists | |||
if (!bf::exists(path)) | |||
throw ElfFileParseError("No such file or directory: " + path.string()); | |||
if (!bf::exists(path) || !bf::is_regular_file(path)) |
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.
Indeed, exists
is redundant here. Please fix.
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.
Unit tests fail due to this change, please check and fix them if needed.
Thanks, the tests should pass now. |
@@ -51,7 +51,7 @@ namespace LinuxDeployTest { | |||
} | |||
|
|||
TEST_F(ElfFileTest, checkInvalidElfHeaderOnEmptyFile) { | |||
expectThrowsElfFileErrorInvalidElfHeader("/dev/null"); | |||
expectThrowsElfFileErrorInvalidElfHeader(EMPTY_FILE_PATH); |
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.
Good idea!
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.
The change was needed since is_regular_file
returns false
for /dev/null
.
0134c88
to
5782892
Compare
I accidentally passed a directory instead of an executable along --executable. The additional check and printing out the filename would have helped me find the error more easily.