Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tmnku
Copy link

@tmnku tmnku commented Feb 12, 2022

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.

Copy link
Member

@TheAssassin TheAssassin left a 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.

@@ -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))
Copy link
Member

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...

Copy link
Member

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.

@@ -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))
Copy link
Member

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.

Copy link
Member

@TheAssassin TheAssassin left a 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.

@tmnku
Copy link
Author

tmnku commented Feb 13, 2022

Thanks, the tests should pass now.

@@ -51,7 +51,7 @@ namespace LinuxDeployTest {
}

TEST_F(ElfFileTest, checkInvalidElfHeaderOnEmptyFile) {
expectThrowsElfFileErrorInvalidElfHeader("/dev/null");
expectThrowsElfFileErrorInvalidElfHeader(EMPTY_FILE_PATH);
Copy link
Member

Choose a reason for hiding this comment

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

Good idea!

Copy link
Author

@tmnku tmnku Feb 21, 2022

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.

@tmnku tmnku requested a review from TheAssassin February 21, 2022 07:03
@TheAssassin TheAssassin force-pushed the check_elffile_is_file branch from 0134c88 to 5782892 Compare May 4, 2022 01:12
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.

2 participants