Skip to content

Commit b3f1913

Browse files
authored
Merge pull request #3354 from AlxCzl/fix-mad-cardholder-overread
Fix buffer over-read in MADCardHolderInfoDecode
2 parents 72ca3bd + 10cd871 commit b3f1913

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

client/src/mifare/mad.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,14 @@ int MADCardHolderInfoDecode(uint8_t *data, size_t datalen, bool verbose) {
291291
uint8_t len = data[idx] & 0x3f;
292292
uint8_t type = data[idx] >> 6;
293293
idx++;
294-
if (len > 0) {
295-
PrintAndLogEx(INFO, "%14s " _GREEN_("%.*s"), holder_info_type[type], len, &data[idx]);
296-
idx += len;
297-
} else {
294+
if (len == 0)
295+
break;
296+
if (idx + len > datalen) {
297+
PrintAndLogEx(WARNING, "Card holder info truncated (need %u bytes, %zu available)", len, datalen - idx);
298298
break;
299299
}
300+
PrintAndLogEx(INFO, "%14s " _GREEN_("%.*s"), holder_info_type[type], len, &data[idx]);
301+
idx += len;
300302
}
301303
return PM3_SUCCESS;
302304
}

0 commit comments

Comments
 (0)