From e4691591454edf2c11697096ea72d650a7dbda79 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 20 Jan 2015 21:58:53 +0100 Subject: [PATCH] FIX: another file_path found in loadTraceCard and saveTraceCard, is now corrected to follow FILE_PATH_SIZE variable. FIX: some filehandles that didn't get closed. --- client/mifarehost.c | 17 +++++++++++++---- client/mifarehost.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/client/mifarehost.c b/client/mifarehost.c index e62d6260..7f784850 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -301,9 +301,9 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) { static uint8_t trailerAccessBytes[4] = {0x08, 0x77, 0x8F, 0x00}; // variables -char logHexFileName[200] = {0x00}; +char logHexFileName[FILE_PATH_SIZE] = {0x00}; static uint8_t traceCard[4096] = {0x00}; -static char traceFileName[200] = {0x00}; +static char traceFileName[FILE_PATH_SIZE] = {0x00}; static int traceState = TRACE_IDLE; static uint8_t traceCurBlock = 0; static uint8_t traceCurKey = 0; @@ -351,10 +351,15 @@ int loadTraceCard(uint8_t *tuid) { FillFileNameByUID(traceFileName, tuid, ".eml", 7); f = fopen(traceFileName, "r"); - if (!f) return 1; + if (!f) { + fclose(f); + return 1; + } blockNum = 0; + while(!feof(f)){ + memset(buf, 0, sizeof(buf)); if (fgets(buf, sizeof(buf), f) == NULL) { PrintAndLog("File reading error."); @@ -386,13 +391,17 @@ int saveTraceCard(void) { if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0; f = fopen(traceFileName, "w+"); + if ( !f ) { + fclose(f); + return 1; + } + for (int i = 0; i < 64; i++) { // blocks for (int j = 0; j < 16; j++) // bytes fprintf(f, "%02x", *(traceCard + i * 16 + j)); fprintf(f,"\n"); } fclose(f); - return 0; } diff --git a/client/mifarehost.h b/client/mifarehost.h index 3e946cd9..96eb75f7 100644 --- a/client/mifarehost.h +++ b/client/mifarehost.h @@ -47,7 +47,7 @@ typedef struct { int foundKey[2]; } sector; -extern char logHexFileName[200]; +extern char logHexFileName[FILE_PATH_SIZE]; int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * ResultKeys, bool calibrate); int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key); -- 2.39.2