-
Notifications
You must be signed in to change notification settings - Fork 893
Open
Description
static int
decrypt_region_inplace(struct enc_key_data *enc_data,
const struct flash_area *fap,
struct image_header *hdr,
uint32_t off, uint32_t sz)
{
uint32_t bytes_copied;
int chunk_sz;
int rc;
uint32_t tlv_off;
size_t blk_off;
uint16_t idx;
uint32_t blk_sz;
uint8_t buf[sz] __attribute__((aligned)); //<<<<<<<<<<<<<<<<<<<
assert(sz <= sizeof buf); //<<<<<<<<<<<<<<<<<<<
There are several problems with this approach. IAR and Keil doesn't enable variable length arrays by default, so it compiles with the error "Error[Pe028]: expression must have a constant value". It is also forbidden by several safety standarts like MISRA.
The sz argument should match sector size which leads to stack overflow risk. If you consider that there are flashless devices what could use a flash memory with sector size like 256kB...
assert check is not enough as it is valid only during development state.
I think it woul be a good idea to rewrite it to static buffer with a size of flash page rather than a sector.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels