bootgen icon indicating copy to clipboard operation
bootgen copied to clipboard

Check elf magic before elf header size

Open hannesweisbach opened this issue 1 year ago • 4 comments

Checking elf header size before elf magic may lead to presenting the user with a misleading error message in case the elf file header is corrupted or a non-elf file was entered into the bif file instead of an elf file (for example bl31.bin instead of bl31.elf.

Instead of receiving the misleading error message:
[ERROR] : ELF Parsing Error !!! Wrong Header Size

The user is now presented with a more accurate error message: [ERROR] : ELF Parsing Error !!! ELF magic identification word wrong

hannesweisbach avatar Jul 05 '23 08:07 hannesweisbach

Aren't both messages printed no matter the order of the checks?

kalvdans avatar Jul 05 '23 09:07 kalvdans

No, LOG_DEBUG calls Logger::Instance()->Error(), which in turn ends with throw BootGenException which is caught in main() and then the application exists.

hannesweisbach avatar Jul 05 '23 09:07 hannesweisbach

I see (you mean LOG_ERROR I presume). Then I agree that your suggested order is more natural.

kalvdans avatar Jul 05 '23 09:07 kalvdans

Yes, LOG_ERROR, of course 😅

hannesweisbach avatar Jul 05 '23 10:07 hannesweisbach