From 2d43d4c021472c3693bb86263788226a8baac755 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 3 Jul 2026 11:20:33 +0200 Subject: [PATCH] fix coverity #910669 --- armsrc/Standalone/hf_mattyrun.c | 31 ++++++++++++++++++++++++------- armsrc/mifarecmd.c | 8 ++++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index fa0710b02..7362ea1a6 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -167,8 +167,13 @@ static int saMifareChkKeys(uint8_t const blockNo, uint8_t const keyType, bool co mfKey &= MATTYRUN_MFC_KEY_BITS; if (mattyrun_card.uidlen == 0) { - if (!saMifareDiscover()) { - --i; // try same key once again + + if (saMifareDiscover() == false) { + + if (i) { + --i; // try same key once again + } + --selectRetries; if (selectRetries > 0) { continue; @@ -177,26 +182,35 @@ static int saMifareChkKeys(uint8_t const blockNo, uint8_t const keyType, bool co break; } } + } else { + if (cascade_levels == 0) { switch (mattyrun_card.uidlen) { - case 4: + case 4: { cascade_levels = 1; break; - case 7: + } + case 7: { cascade_levels = 2; break; - case 10: + } + case 10: { cascade_levels = 3; break; - default: + } + default: { break; + } } } // No need for anticollision. Since we sucessfully selected the card before, // we can directly select the card again if (iso14443a_fast_select_card(mattyrun_uid, cascade_levels) == 0) { - --i; // try same key once again + if (i) { + --i; // try same key once again + } + --selectRetries; if (selectRetries > 0) { continue; @@ -211,10 +225,12 @@ static int saMifareChkKeys(uint8_t const blockNo, uint8_t const keyType, bool co authres = mifare_classic_auth(pcs, mattyrun_cuid, blockNo, keyType, mfKey, AUTH_FIRST); if (authres) { + uint8_t dummy_answer = 0; ReaderTransmit(&dummy_answer, 1, NULL); // wait for the card to become ready again SpinDelayUs(AUTHENTICATION_TIMEOUT); + if (authres == 1) { retval = -3; break; @@ -222,6 +238,7 @@ static int saMifareChkKeys(uint8_t const blockNo, uint8_t const keyType, bool co continue; } } + *key = mfKey; retval = i; break; diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 15ca3248c..ce0801cf1 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2562,7 +2562,9 @@ void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) { iso14a_card_select_t card_info; if (iso14443a_select_card(uid, &card_info, &cuid, true, 0, true) == false) { if (g_dbglevel >= DBG_ERROR) Dbprintf("ChkKeys: Can't select card (ALL)"); - --i; // try same key once again + if (i) { + --i; // try same key once again + } continue; } switch (card_info.uidlen) { @@ -2582,7 +2584,9 @@ void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) { } else { // no need for anticollision. We can directly select the card if (iso14443a_select_card(uid, NULL, NULL, false, cascade_levels, true) == false) { if (g_dbglevel >= DBG_ERROR) Dbprintf("ChkKeys: Can't select card (UID)"); - --i; // try same key once again + if (i) { + --i; // try same key once again + } continue; } }