From fcde2978a8ffe1ccbb86d8ed9103a8c792da47a8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 24 Jul 2023 15:11:21 +0200 Subject: [PATCH] coverity believes somehow the return value from mfSectorNum can be 31. And wants us to check that it is only same size as sectors allocated --- client/src/cmdhfmf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 6f28d7d7c..bbeaa5fce 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -376,13 +376,14 @@ static int mf_print_keys(uint16_t n, uint8_t *d) { } for (uint16_t i = 0; i < n; i++) { - if (mfIsSectorTrailer(i)) { - uint8_t sec = mfSectorNum(i); - e_sector[sec].foundKey[0] = 1; - e_sector[sec].Key[0] = bytes_to_num(d + (i * MFBLOCK_SIZE), MIFARE_KEY_SIZE); - e_sector[sec].foundKey[1] = 1; - e_sector[sec].Key[1] = bytes_to_num(d + (i * MFBLOCK_SIZE) + 10, MIFARE_KEY_SIZE); + if (mfIsSectorTrailer(i) == false) { + continue; } + uint8_t sec = MIN(sectors, mfSectorNum(i)); + e_sector[sec].foundKey[0] = 1; + e_sector[sec].Key[0] = bytes_to_num(d + (i * MFBLOCK_SIZE), MIFARE_KEY_SIZE); + e_sector[sec].foundKey[1] = 1; + e_sector[sec].Key[1] = bytes_to_num(d + (i * MFBLOCK_SIZE) + 10, MIFARE_KEY_SIZE); } printKeyTable(sectors, e_sector); free(e_sector);