Skip to content

remove stink of corruption from scanelf.d#5938

Merged
andralex merged 1 commit intodlang:masterfrom
WalterBright:scanelf3
Jul 19, 2016
Merged

remove stink of corruption from scanelf.d#5938
andralex merged 1 commit intodlang:masterfrom
WalterBright:scanelf3

Conversation

@WalterBright
Copy link
Member

Should no longer crash when fed a corrupt object file. Switched to arrays rather than pointer arithmetic. Removed dead code. Removed use of goto. Simplified error handling.

@UplinkCoder
Copy link
Member

I like this, looking goo.d.
Thanks for getting rid of the goto.

src/scanelf.d Outdated
if (base.length < Elf32_Ehdr.sizeof)
return corrupt(__LINE__);

immutable ubyte[4] elf = [0x7F, 'E', 'L', 'F']; // ELF file signature
Copy link
Member

Choose a reason for hiding this comment

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

make it static lest you end up initializing it every pass through the function

Copy link
Member

Choose a reason for hiding this comment

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

(this is the only holdup)

Copy link
Contributor

Choose a reason for hiding this comment

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

LDC will emit this into the data segment just as well. No idea about DMD, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

DMD makes immutables static anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

sigh

@andralex
Copy link
Member

Please fix the byte[4]

if (base.length < Elf32_Ehdr.sizeof)
return corrupt(__LINE__);

static immutable ubyte[4] elf = [0x7F, 'E', 'L', 'F']; // ELF file signature
Copy link
Member

Choose a reason for hiding this comment

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

@andralex
Copy link
Member

Auto-merge toggled on

@andralex andralex merged commit b611c11 into dlang:master Jul 19, 2016
@WalterBright WalterBright deleted the scanelf3 branch July 20, 2016 03:36
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.

6 participants