Skip to content

check if elffile is a file, make exception more descriptive#193

Open
tmnku wants to merge 3 commits intolinuxdeploy:masterfrom
tmnku:check_elffile_is_file
Open

check if elffile is a file, make exception more descriptive#193
tmnku wants to merge 3 commits intolinuxdeploy:masterfrom
tmnku:check_elffile_is_file

Conversation

@tmnku
Copy link
Copy Markdown

@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
Copy Markdown
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.

// 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
Copy Markdown
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
Copy Markdown
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.

// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

tmnku commented Feb 13, 2022

Thanks, the tests should pass now.


TEST_F(ElfFileTest, checkInvalidElfHeaderOnEmptyFile) {
expectThrowsElfFileErrorInvalidElfHeader("/dev/null");
expectThrowsElfFileErrorInvalidElfHeader(EMPTY_FILE_PATH);
Copy link
Copy Markdown
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
Copy Markdown
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