Skip to content

Commit b588977

Browse files
guitsytom-van
authored andcommitted
flash/nor/cfi: fix uninitialized write-mem pointer
In flash/nor/cfi.c:835 struct cfi_info is allocated by malloc(). As write-mem was uninitialized the pointer pointed to an out of range address, which led to a segmentation fault and crashed openocd. This happened during flash-command of an external flash-bank, using cfi. Use calloc() instead. While on it check for NULL return and remove unnecessary initialzation. Change-Id: I0e2ffb90559afe7f090837023428dcc06b2e29f6 Signed-off-by: Mischa Studer <[email protected]> Reviewed-on: http://openocd.zylin.com/6070 Tested-by: jenkins Reviewed-by: Tomas Vanek <[email protected]>
1 parent 6448f70 commit b588977

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/flash/nor/cfi.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -832,17 +832,13 @@ int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **
832832
return ERROR_FLASH_BANK_INVALID;
833833
}
834834

835-
cfi_info = malloc(sizeof(struct cfi_flash_bank));
836-
cfi_info->probed = false;
837-
cfi_info->erase_region_info = NULL;
838-
cfi_info->pri_ext = NULL;
835+
cfi_info = calloc(1, sizeof(struct cfi_flash_bank));
836+
if (cfi_info == NULL) {
837+
LOG_ERROR("No memory for flash bank info");
838+
return ERROR_FAIL;
839+
}
839840
bank->driver_priv = cfi_info;
840841

841-
cfi_info->x16_as_x8 = false;
842-
cfi_info->jedec_probe = false;
843-
cfi_info->not_cfi = false;
844-
cfi_info->data_swap = false;
845-
846842
for (unsigned i = 6; i < argc; i++) {
847843
if (strcmp(argv[i], "x16_as_x8") == 0)
848844
cfi_info->x16_as_x8 = true;

0 commit comments

Comments
 (0)