Skip to content

Commit ebe431b

Browse files
authored
Merge pull request #3023 from aaronjamt/patch-1
Proper TLV parsing for Seos
2 parents 210b9a7 + 9ee9b1a commit ebe431b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

client/src/cmdhfseos.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,24 @@ static int select_DF_verify(uint8_t *response, uint8_t response_length, uint8_t
550550
// Extract everything before the 8E tag
551551

552552
int res = PM3_EWRONGANSWER;
553-
for (int i = 0; i < response_length; i++) {
553+
for (int i = 0; i < response_length - 2;) {
554554
// extract MAC
555555
if (response[i] == 0x8E) {
556+
if (response[i+1] != MAC_value_len) {
557+
goto out;
558+
}
559+
// Ensure there's enough bytes remaining
560+
// in the response for the full MAC
561+
if (i+2+MAC_value_len > response_length) {
562+
goto out;
563+
}
556564
memcpy(input, response, i);
557565
memcpy(MAC_value, response + (i + 2), MAC_value_len);
558566
res = PM3_SUCCESS;
559567
break;
560568
}
569+
// skip to next tag
570+
i += 2 + response[i+1];
561571
}
562572
if (res != PM3_SUCCESS) {
563573
goto out;

0 commit comments

Comments
 (0)