Skip to content

Commit 458acf4

Browse files
authored
Merge pull request #3353 from AlxCzl/fix-mad1-loop-oob
Fix MAD1 off-by-one in MADDecode: loop read Key A as 16th AID
2 parents b3f1913 + 6aa8a2f commit 458acf4

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

client/src/mifare/mad.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ int MADDecode(uint8_t *sector0, uint8_t *sector16, uint16_t *mad, size_t *madlen
264264
PrintAndLogEx(INFO, "overriding crc check");
265265
}
266266

267-
// 7 + 8 == 15
268-
for (int i = 1; i <= 16; i++) {
267+
for (int i = 1; i < 16; i++) {
269268
mad[*madlen] = madGetAID(sector0, swapmad, 1, i);
270269
(*madlen)++;
271270
}

client/src/mifare/mad.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
#include "common.h"
2323

24-
// 16 MAD1 AIDs + 1 MAD2 marker (0x0005) + 23 MAD2 AIDs = 40
25-
#define MAD_MAX_AID_ENTRIES 40
24+
// 15 MAD1 AIDs (sectors 1-15) + 1 MAD2 marker (0x0005) + 23 MAD2 AIDs (sectors 17-39) = 39
25+
#define MAD_MAX_AID_ENTRIES 39
2626

2727
int MADCheck(uint8_t *sector0, uint8_t *sector16, bool verbose, bool *haveMAD2);
2828
int MADDecode(uint8_t *sector0, uint8_t *sector16, uint16_t *mad, size_t *madlen, bool swapmad, bool override);

0 commit comments

Comments
 (0)