Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could be simplified a bit (mostly removing the duplicated check of
y.p_type == PT_PHDR
:Comments are just suggestions.
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.
While it does seem worth fixing this, according to documents such as [1][2] it seems that only a single
PT_PHDR
entry may legally exist in a file.Thinking about what
PT_PHDR
actually means, this makes sense :). Also my comments are indeed a bit silly, I didn't have my "ELF-knowledge hat" on.So this is probably harmless as-is: for any legal set of segments this operator will define a valid (strict weak) ordering.
Might be worth ensuring we reject files that attempt to have multiple PT_PHDR segments?
[1] http://www.sco.com/developers/gabi/latest/ch5.pheader.html
[2] http://www.skyfree.org/linux/references/ELF_Format.pdf
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've simplified the code now. Thanks.
Yes, this was found using a debug version of std::sort, not by obviously incorrect results. Since there's only a single PT_PHDR entry, It probably doesn't any difference on any sane implementation of std::sort, but it is undefined behavior, so there's no guarantees about that.