Skip to content

Instantly share code, notes, and snippets.

@fishsoupisgood
Last active February 22, 2018 11:00
Show Gist options
  • Save fishsoupisgood/f4575d7cc8db2e48dae1bac356e9e0b6 to your computer and use it in GitHub Desktop.
Save fishsoupisgood/f4575d7cc8db2e48dae1bac356e9e0b6 to your computer and use it in GitHub Desktop.
potential patch
diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c
--- a/src/libopensc/asn1.c
+++ b/src/libopensc/asn1.c
@@ -477,6 +477,10 @@ const u8 *sc_asn1_find_tag(sc_context_t *ctx, const u8 * buf,
/* read a tag */
if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS)
return NULL;
+
+ if (!p)
+ return NULL;
+
left -= (p - buf);
/* we need to shift the class byte to the leftmost
* byte of the tag */
diff --git a/src/libopensc/card-gids.c b/src/libopensc/card-gids.c
--- a/src/libopensc/card-gids.c
+++ b/src/libopensc/card-gids.c
@@ -533,17 +533,19 @@ static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_lef
r = gids_get_DO(card, GIDS_APPLET_EFID, dataObjectIdentifier, buffer, &buffersize);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the masterfile");
- p = sc_asn1_find_tag(card->ctx, buffer, sizeof(buffer), GIDS_TRY_COUNTER_OLD_TAG, &datasize);
+ buffersize = buffersize > sizeof(buffer) ? sizeof(buffer) : buffersize;
+
+ p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_OLD_TAG, &datasize);
if (p && datasize == 1) {
if (tries_left)
*tries_left = p[0];
}
- p = sc_asn1_find_tag(card->ctx, buffer, sizeof(buffer), GIDS_TRY_COUNTER_TAG, &datasize);
+ p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_TAG, &datasize);
if (p && datasize == 1) {
if (tries_left)
*tries_left = p[0];
}
- p = sc_asn1_find_tag(card->ctx, buffer, sizeof(buffer), GIDS_TRY_LIMIT_TAG, &datasize);
+ p = sc_asn1_find_tag(card->ctx, buffer, buffersize , GIDS_TRY_LIMIT_TAG, &datasize);
if (p && datasize == 1) {
if (tries_left)
*max_tries = p[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment