Skip to content

Commit

Permalink
cardos: Correctly calculate the left bytes to avoid buffer overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakuje authored and frankmorgner committed Feb 25, 2021
1 parent 17d8980 commit 1252aca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libopensc/card-cardos.c
Expand Up @@ -159,7 +159,7 @@ static int cardos_have_2048bit_package(sc_card_t *card)
sc_apdu_t apdu;
u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
int r;
const u8 *p = rbuf, *q;
const u8 *p = rbuf, *q, *pp;
size_t len, tlen = 0, ilen = 0;

sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x88);
Expand All @@ -175,10 +175,10 @@ static int cardos_have_2048bit_package(sc_card_t *card)
return 0;

while (len != 0) {
p = sc_asn1_find_tag(card->ctx, p, len, 0xe1, &tlen);
if (p == NULL)
pp = sc_asn1_find_tag(card->ctx, p, len, 0xe1, &tlen);
if (pp == NULL)
return 0;
q = sc_asn1_find_tag(card->ctx, p, tlen, 0x01, &ilen);
q = sc_asn1_find_tag(card->ctx, pp, tlen, 0x01, &ilen);
if (q == NULL || ilen != 4)
return 0;
if (q[0] == 0x1c)
Expand Down

0 comments on commit 1252aca

Please sign in to comment.