From 81a9807c39505af23425308fd40662d6b886bde9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 15:05:52 +0700 Subject: [PATCH] fileutils: clear *pdata after freeing it on a load error loadFile_safeEx, loadFile_TXTsafe, loadFileEML_safe and loadFileMCT_safe freed *pdata on a short read or a failed realloc but left the caller's pointer set, so a caller keeping it freed it again. Same as loadFileDICTIONARY_safe_ex already does. Co-Authored-By: Claude Opus 5.5 --- client/src/fileutils.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 5df788234..2a2e710d5 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -1973,6 +1973,7 @@ int loadFile_safeEx(const char *preferredName, const char *suffix, void **pdata, if (bytes_read != fsize) { PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); free(*pdata); + *pdata = NULL; return PM3_EFILE; } @@ -2025,6 +2026,7 @@ int loadFile_TXTsafe(const char *preferredName, const char *suffix, void **pdata if (bytes_read != fsize) { PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); free(*pdata); + *pdata = NULL; return PM3_EFILE; } @@ -2112,6 +2114,7 @@ int loadFileEML_safe(const char *preferredName, void **pdata, size_t *datalen) { if (newdump == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); free(*pdata); + *pdata = NULL; return PM3_EMALLOC; } else { *pdata = newdump; @@ -2591,6 +2594,7 @@ int loadFileMCT_safe(const char *preferredName, void **pdata, size_t *datalen) { if (newdump == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); free(*pdata); + *pdata = NULL; return PM3_EMALLOC; } else { *pdata = newdump;