From ea378a7bdb3bed67ad52b1bd05911eea85f8b34f Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Thu, 23 Jun 2011 23:35:16 +0200 Subject: check if we have enough memory before casting Signed-off-by: Michael Olbrich --- common/EncoreBootImage.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/EncoreBootImage.cpp b/common/EncoreBootImage.cpp index 26b1194..d747bfb 100644 --- a/common/EncoreBootImage.cpp +++ b/common/EncoreBootImage.cpp @@ -698,6 +698,7 @@ void EncoreBootImage::BootCommand::validateHeader(const boot_command_t * modelHe //! \exception std::runtime_error Thrown if header fields are invalid. void EncoreBootImage::NopCommand::initFromData(const cipher_block_t * blocks, unsigned count, unsigned * consumed) { + assert((sizeof(cipher_block_t) * count) == sizeof(boot_command_t)); const boot_command_t model = { 0, ROM_NOP_CMD, 0, 0, 0, 0 }; const boot_command_t * header = reinterpret_cast(blocks); validateHeader(&model, header, CMD_TAG_FIELD | CMD_FLAGS_FIELD | CMD_ADDRESS_FIELD | CMD_COUNT_FIELD | CMD_DATA_FIELD); @@ -744,6 +745,7 @@ EncoreBootImage::TagCommand::TagCommand(const Section & section) //! \exception std::runtime_error Thrown if header fields are invalid. void EncoreBootImage::TagCommand::initFromData(const cipher_block_t * blocks, unsigned count, unsigned * consumed) { + assert((sizeof(cipher_block_t) * count) == sizeof(boot_command_t)); const boot_command_t model = { 0, ROM_TAG_CMD, 0, 0, 0, 0 }; const boot_command_t * header = reinterpret_cast(blocks); validateHeader(&model, header, CMD_TAG_FIELD); @@ -801,6 +803,7 @@ EncoreBootImage::LoadCommand::LoadCommand(uint32_t address, const uint8_t * data //! specified in the command header or if header fields are invalid. void EncoreBootImage::LoadCommand::initFromData(const cipher_block_t * blocks, unsigned count, unsigned * consumed) { + assert((sizeof(cipher_block_t) * count) == sizeof(boot_command_t)); // check static fields const boot_command_t model = { 0, ROM_LOAD_CMD, 0, 0, 0, 0 }; const boot_command_t * header = reinterpret_cast(blocks); @@ -995,6 +998,7 @@ EncoreBootImage::FillCommand::FillCommand() //! \exception std::runtime_error Thrown if header fields are invalid. void EncoreBootImage::FillCommand::initFromData(const cipher_block_t * blocks, unsigned count, unsigned * consumed) { + assert((sizeof(cipher_block_t) * count) == sizeof(boot_command_t)); // check static fields const boot_command_t model = { 0, ROM_FILL_CMD, 0, 0, 0, 0 }; const boot_command_t * header = reinterpret_cast(blocks); @@ -1051,6 +1055,7 @@ void EncoreBootImage::FillCommand::debugPrint() const //! \exception std::runtime_error Thrown if header fields are invalid. void EncoreBootImage::ModeCommand::initFromData(const cipher_block_t * blocks, unsigned count, unsigned * consumed) { + assert((sizeof(cipher_block_t) * count) == sizeof(boot_command_t)); // check static fields const boot_command_t model = { 0, ROM_MODE_CMD, 0, 0, 0, 0 }; const boot_command_t * header = reinterpret_cast(blocks); @@ -1086,6 +1091,7 @@ void EncoreBootImage::ModeCommand::debugPrint() const //! \exception std::runtime_error Thrown if header fields are invalid. void EncoreBootImage::JumpCommand::initFromData(const cipher_block_t * blocks, unsigned count, unsigned * consumed) { + assert((sizeof(cipher_block_t) * count) == sizeof(boot_command_t)); // check static fields const boot_command_t model = { 0, getTag(), 0, 0, 0, 0 }; const boot_command_t * header = reinterpret_cast(blocks); -- cgit v1.2.3