-
Notifications
You must be signed in to change notification settings - Fork 101
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
base: master
Are you sure you want to change the base?
Conversation
16527d1
to
a437584
Compare
+1 for this |
@@ -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) { |
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.
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.
for (unsigned i = 0; i < m->hdr.shnum; i++) { | ||
const void *sec = ((const char*)sec_data) + i * m->hdr.shentsize; | ||
if (NULL == sec) { |
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.
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.
@@ -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) { |
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.
Please follow the coding conventions of the surrounding code, which uses forward comparison: sec_data == NULL
.
File with the hash of ee4b726d2601b084e02f4fb7411a26054fa8a1053f011d3ee9d5a422d93f342c was crashing this parser.