Skip to content

Commit 7d1ef20

Browse files
committed
fix: "array out of bounds" error leading to memory corruption
Fix description ---------------- add missing checks on the index of nor_flash -> lx_nor_flash_extended_cache[i] Fixes Issue#58 Signed-off-by: Haithem Rahmani <haithem.rahmani@st.com>
1 parent 04e385f commit 7d1ef20

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

common/src/lx_nor_flash_extended_cache_enable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ ULONG block_word;
290290

291291
/* Loop through the memory supplied and assign to cache entries. */
292292
i = 0;
293-
while (cache_size >= LX_NOR_SECTOR_SIZE)
293+
while ((cache_size >= LX_NOR_SECTOR_SIZE) && (i < LX_NOR_EXTENDED_CACHE_SIZE))
294294
{
295295

296296
/* Setup this cache entry. */
@@ -309,7 +309,7 @@ ULONG block_word;
309309
}
310310

311311
/* Save the number of cache entries. */
312-
if(i > LX_NOR_EXTENDED_CACHE_SIZE)
312+
if(i == LX_NOR_EXTENDED_CACHE_SIZE)
313313
{
314314

315315
nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE;

0 commit comments

Comments
 (0)