Skip to content
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

Safer sections iteration #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions elf/elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ elf::elf(const std::shared_ptr<loader> &l)
// Load sections
const void *sec_data = l->load(m->hdr.shoff,
m->hdr.shentsize * m->hdr.shnum);
if (NULL == sec_data) {
Copy link
Owner

Choose a reason for hiding this comment

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

loader.load is not allowed to return NULL (it's supposed to throw an exception if there's a problem) and the mmap loader implementation doesn't return NULL, so I'm afraid I don't understand what this change is accomplishing.

Copy link
Owner

Choose a reason for hiding this comment

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

Please follow the coding conventions of the surrounding code, which uses forward comparison: sec_data == NULL.

return;
}
for (unsigned i = 0; i < m->hdr.shnum; i++) {
const void *sec = ((const char*)sec_data) + i * m->hdr.shentsize;
if (NULL == sec) {
Copy link
Owner

Choose a reason for hiding this comment

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

It doesn't make sense for sec to be NULL here, since it's a result from a pointer offset from sec_data. In practice the only way this can happen is if sec_data itself is NULL, but then we shouldn't have even done the pointer arithmetic.

continue;
}
// XXX Circular reference. Maybe this should be
// constructed on the fly? Canonicalizing the header
// isn't super-cheap.
Expand Down