Merge pull request #1818 from DidierA/hf_mfu_esave

use calloc(), not malloc()
This commit is contained in:
Iceman 2022-11-24 03:48:08 +01:00 committed by GitHub
commit bad56a74ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4102,20 +4102,20 @@ int CmdHF14MfuNDEFRead(const char *Cmd) {
// utility function. Retrieves emulator memory // utility function. Retrieves emulator memory
static int GetMfuDumpFromEMul(mfu_dump_t **buf) { static int GetMfuDumpFromEMul(mfu_dump_t **buf) {
uint8_t *dump = malloc(sizeof(mfu_dump_t)); mfu_dump_t *dump = calloc(1, sizeof(mfu_dump_t));
if (dump == NULL) { if (dump == NULL) {
PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
return PM3_EMALLOC; return PM3_EMALLOC;
} }
PrintAndLogEx(INFO, "downloading from emulator memory"); PrintAndLogEx(INFO, "downloading from emulator memory");
if (!GetFromDevice(BIG_BUF_EML, dump, sizeof(mfu_dump_t), 0, NULL, 0, NULL, 2500, false)) { if (!GetFromDevice(BIG_BUF_EML, (uint8_t *)dump, MFU_MAX_BYTES + MFU_DUMP_PREFIX_LENGTH, 0, NULL, 0, NULL, 2500, false)) {
PrintAndLogEx(WARNING, "Fail, transfer from device time-out"); PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
free(dump); free(dump);
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
*buf = (mfu_dump_t *)dump ; *buf = dump ;
return PM3_SUCCESS ; return PM3_SUCCESS ;
} }