-
Notifications
You must be signed in to change notification settings - Fork 496
Add PEM command line flag for enforcing a max file size for ElfReader #2194
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ namespace px { | |
| namespace stirling { | ||
| namespace obj_tools { | ||
|
|
||
| constexpr std::string_view kDebugFileDir = "/usr/lib/debug"; | ||
|
|
||
| class ElfReader { | ||
| public: | ||
| /** | ||
|
|
@@ -50,8 +52,14 @@ class ElfReader { | |
| * @return error if could not setup elf reader. | ||
| */ | ||
| static StatusOr<std::unique_ptr<ElfReader>> Create( | ||
| const std::string& binary_path, | ||
| const std::filesystem::path& debug_file_dir = "/usr/lib/debug"); | ||
| const std::string& binary_path, const std::filesystem::path& debug_file_dir = kDebugFileDir); | ||
|
|
||
| /** | ||
| * Creates an ElfReader that does not enforce the max file size limit. This is useful for cases | ||
| * where the binary size is known in advance or the binary must be loaded regardless of size. | ||
| */ | ||
| static StatusOr<std::unique_ptr<ElfReader>> CreateUncapped( | ||
| const std::string& binary_path, const std::filesystem::path& debug_file_dir = kDebugFileDir); | ||
|
Comment on lines
+55
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From an API perspective, it might be simpler to have a single Create() where the size is an optional parameter that defaults to FLAGS_elf_reader_max_file_size. What do you think?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to changing this, but I wanted to make the uncapped behavior an explicit opt-in for consumers of ElfReader. Since it's used in many places, I could see a future bug where the max file size check is unintentionally bypassed when most consumers should retain the restriction.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We talked about this offline, but the suggestion is that the optional parameter defaults to the capped version, so I don't think it exposes any risk. The goal is just to keep the API simpler. But this is a bit subjective, so doesn't need to be a blocker if you prefer the two separate API calls. |
||
|
|
||
| std::filesystem::path& debug_symbols_path() { return debug_symbols_path_; } | ||
|
|
||
|
|
@@ -207,6 +215,9 @@ class ElfReader { | |
| } | ||
|
|
||
| private: | ||
| static StatusOr<std::unique_ptr<ElfReader>> CreateImpl( | ||
| const std::string& binary_path, const std::filesystem::path& debug_file_dir); | ||
|
|
||
| ElfReader() = default; | ||
|
|
||
| StatusOr<ELFIO::section*> SymtabSection(); | ||
|
|
||
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'd put much of this in a helper function StatusOr GetFileSize(), which can return an error in the case of file_size < 0. Then you can do:
which is a bit more focused.
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.
Makes sense. I've refactored this and relocated to the fs_wrapper code in 9d48a38.