From af4f7083ea92931a07e47995eb2bc2a348c577ed Mon Sep 17 00:00:00 2001 From: Ramya Darapuneni Date: Thu, 3 Nov 2022 15:33:42 +0530 Subject: [PATCH 1/3] Fix build on machines with modern flex This is to address pull request https://github.com/Xilinx/bootgen/pull/20 --- FlexLexer.h | 8 +++----- bif.yy.cpp | 2 +- bifscanner.h | 2 +- cmdoptions.yy.cpp | 2 +- cmdoptionsscanner.h | 2 +- reginit.yy.cpp | 2 +- reginitscanner.h | 2 +- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/FlexLexer.h b/FlexLexer.h index b115b5d..a06fb21 100755 --- a/FlexLexer.h +++ b/FlexLexer.h @@ -33,15 +33,15 @@ // // If you want to create multiple lexer classes, you use the -P flag // to rename each yyFlexLexer to some other xxFlexLexer. You then -// include in your other sources once per lexer class: +// include "FlexLexer.h" in your other sources once per lexer class: // // #undef yyFlexLexer // #define yyFlexLexer xxFlexLexer -// #include +// #include "FlexLexer.h" // // #undef yyFlexLexer // #define yyFlexLexer zzFlexLexer -// #include +// #include "FlexLexer.h" // ... #ifndef __FLEX_LEXER_H @@ -204,5 +204,3 @@ class yyFlexLexer : public FlexLexer { #endif // yyFlexLexer || ! yyFlexLexerOnce - -// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689 diff --git a/bif.yy.cpp b/bif.yy.cpp index 5e357d1..8f652bc 100644 --- a/bif.yy.cpp +++ b/bif.yy.cpp @@ -379,7 +379,7 @@ typedef unsigned char YY_CHAR; #define yytext_ptr yytext -#include +#include "FlexLexer.h" int yyFlexLexer::yywrap() { return 1; } int yyFlexLexer::yylex() diff --git a/bifscanner.h b/bifscanner.h index a6ec9e4..ded78da 100755 --- a/bifscanner.h +++ b/bifscanner.h @@ -28,7 +28,7 @@ #if ! defined(yyFlexLexerOnce) #undef yyFlexLexer #define yyFlexLexer bifFlexLexer -#include +#include "FlexLexer.h" #endif // Override the interface for yylex since we namespaced it diff --git a/cmdoptions.yy.cpp b/cmdoptions.yy.cpp index d8fd6ce..1484981 100644 --- a/cmdoptions.yy.cpp +++ b/cmdoptions.yy.cpp @@ -379,7 +379,7 @@ typedef unsigned char YY_CHAR; #define yytext_ptr yytext -#include +#include "FlexLexer.h" int yyFlexLexer::yywrap() { return 1; } int yyFlexLexer::yylex() diff --git a/cmdoptionsscanner.h b/cmdoptionsscanner.h index a48af09..e02c1f1 100755 --- a/cmdoptionsscanner.h +++ b/cmdoptionsscanner.h @@ -29,7 +29,7 @@ #undef yyFlexLexer #define yyFlexLexer reginitFlexLexer -#include +#include "FlexLexer.h" #endif // Override the interface for yylex since we namespaced it diff --git a/reginit.yy.cpp b/reginit.yy.cpp index 8422867..ff088f9 100644 --- a/reginit.yy.cpp +++ b/reginit.yy.cpp @@ -379,7 +379,7 @@ typedef unsigned char YY_CHAR; #define yytext_ptr yytext -#include +#include "FlexLexer.h" int yyFlexLexer::yywrap() { return 1; } int yyFlexLexer::yylex() diff --git a/reginitscanner.h b/reginitscanner.h index 4e78af9..23177be 100755 --- a/reginitscanner.h +++ b/reginitscanner.h @@ -29,7 +29,7 @@ #undef yyFlexLexer #define yyFlexLexer reginitFlexLexer -#include +#include "FlexLexer.h" #endif // Override the interface for yylex since we namespaced it From 1795f18361caf1536d76ffe40ae3cb66e212b020 Mon Sep 17 00:00:00 2001 From: Ramya Darapuneni Date: Fri, 24 Feb 2023 15:32:24 +0530 Subject: [PATCH 2/3] Replacing myrand() with rand() Fix for https://github.com/Xilinx/bootgen/issues/22 --- encryption.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/encryption.cpp b/encryption.cpp index 6495bae..6a7072a 100755 --- a/encryption.cpp +++ b/encryption.cpp @@ -319,7 +319,7 @@ static uint32_t GetRandomValue(uint32_t maxValue) do { - returnValue = (myrand() / (int)(((unsigned)RAND_MAX + 1) / maxValue)); + returnValue = (rand() / (int)(((unsigned)RAND_MAX + 1) / maxValue)); } while (returnValue > maxValue); return returnValue; @@ -642,4 +642,4 @@ void AesGcmEncryptionContext::AesGcm256Decrypt(unsigned char* gcm_pt, int& pt_le EVP_CIPHER_CTX_free(ctx); pt_len = outlen + tmplen; -} \ No newline at end of file +} From 9ea1b0950a518e45bfeeea9e66a4f5c3a3b9c9d2 Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 5 Jul 2023 10:59:22 +0200 Subject: [PATCH 3/3] Check elf magic before elf header size 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 --- elftools.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/elftools.cpp b/elftools.cpp index 7674e39..19b05de 100755 --- a/elftools.cpp +++ b/elftools.cpp @@ -127,18 +127,18 @@ ElfFormat32::ElfFormat32(uint8_t* start) elfHdrEntryCount = 1; /* Basic ELF checks */ - if(ELFHdrEntrySize() != sizeof(Elf32_Ehdr)) - { - LOG_DEBUG(DEBUG_STAMP, "ELF Header size wrong - %d, actual size - %d", ELFHdrEntrySize(), sizeof(Elf64_Ehdr)); - LOG_ERROR("ELF Parsing Error !!!\n Wrong Header Size"); - } - if (memcmp(header.e_ident, ELFMAG, 4) != 0) { LOG_DEBUG(DEBUG_STAMP, "ELF magic identification word wrong"); LOG_ERROR("ELF Parsing Error !!!\n ELF magic identification word wrong"); } + if(ELFHdrEntrySize() != sizeof(Elf32_Ehdr)) + { + LOG_DEBUG(DEBUG_STAMP, "ELF Header size wrong - %d, actual size - %d", ELFHdrEntrySize(), sizeof(Elf64_Ehdr)); + LOG_ERROR("ELF Parsing Error !!!\n Wrong Header Size"); + } + /* If a Section header is defined, get its pointer and its record size count. Otherwise, default it to NULL. */ if(header.e_shoff == 0) @@ -495,18 +495,18 @@ ElfFormat64::ElfFormat64(uint8_t* start) /* Get the header's size. For completeness, tell upper layers that we only have one record. */ elfHdrEntryCount = 1; - - if( ELFHdrEntrySize() != sizeof( Elf64_Ehdr ) ) - { - LOG_DEBUG(DEBUG_STAMP, "ELF Header size wrong - %d, actual size - %d", ELFHdrEntrySize(), sizeof(Elf64_Ehdr)); - LOG_ERROR("ELF Parsing Error !!!\n Wrong Header Size"); - } - + if ( memcmp( header.e_ident, ELFMAG, 4 ) != 0 ) { LOG_DEBUG(DEBUG_STAMP, "ELF magic identification word wrong"); LOG_ERROR("ELF Parsing Error !!!\n ELF magic identification word wrong"); } + + if( ELFHdrEntrySize() != sizeof( Elf64_Ehdr ) ) + { + LOG_DEBUG(DEBUG_STAMP, "ELF Header size wrong - %d, actual size - %d", ELFHdrEntrySize(), sizeof(Elf64_Ehdr)); + LOG_ERROR("ELF Parsing Error !!!\n Wrong Header Size"); + } /* If a Section header is defined, get its pointer and its record size count. Otherwise, default it to NULL. */