Skip to content

Commit 10cd871

Browse files
committed
Fix buffer over-read in MADCardHolderInfoDecode
1 parent c46b72e commit 10cd871

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
@@ -289,12 +289,14 @@ int MADCardHolderInfoDecode(uint8_t *data, size_t datalen, bool verbose) {
289289
uint8_t len = data[idx] & 0x3f;
290290
uint8_t type = data[idx] >> 6;
291291
idx++;
292-
if (len > 0) {
293-
PrintAndLogEx(INFO, "%14s " _GREEN_("%.*s"), holder_info_type[type], len, &data[idx]);
294-
idx += len;
295-
} else {
292+
if (len == 0)
293+
break;
294+
if (idx + len > datalen) {
295+
PrintAndLogEx(WARNING, "Card holder info truncated (need %u bytes, %zu available)", len, datalen - idx);
296296
break;
297297
}
298+
PrintAndLogEx(INFO, "%14s " _GREEN_("%.*s"), holder_info_type[type], len, &data[idx]);
299+
idx += len;
298300
}
299301
return PM3_SUCCESS;
300302
}

0 commit comments

Comments
 (0)