diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2011-06-23 23:35:16 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2011-06-24 14:44:06 +0200 |
commit | ea378a7bdb3bed67ad52b1bd05911eea85f8b34f (patch) | |
tree | 2d4f528890aac53ee2f4fb2d52bfb6e2ae6e64a5 | |
parent | ff0805997c248f1aad24e8b1b3d3ec76c06aa579 (diff) | |
download | mxs-utils-ea378a7bdb3bed67ad52b1bd05911eea85f8b34f.tar.gz mxs-utils-ea378a7bdb3bed67ad52b1bd05911eea85f8b34f.tar.xz |
check if we have enough memory before casting
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r-- | common/EncoreBootImage.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
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<const boot_command_t *>(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<const boot_command_t *>(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<const boot_command_t *>(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<const boot_command_t *>(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<const boot_command_t *>(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<const boot_command_t *>(blocks); |