Skip to content

Commit

Permalink
Fix #1731 sc_format_apdu_cse_lc_le fails to set Le correctly
Browse files Browse the repository at this point in the history
Changed four places where "<" should be "<=" so Le will be set correctly
Previous for 65K (extended) or 256 (short) Le is left set to 0.
This then caused Le to be to be not added to APDU as Le==0
Code later converts actual Le in APDU to be set to 0 to mean 256 or 65K.

SC_APDU_CASE_*_EXT are changed to SC_APDU_CASE_* so sc_detect_apdu_cse
to set the cse based on card capabilities as well as data chaining.

This commit is not well tested and neds review.

 On branch fix-1731
 Changes to be committed:
	modified:   src/libopensc/card.c
  • Loading branch information
dengert authored and frankmorgner committed Sep 9, 2019
1 parent 28a93fd commit 3b632e6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/libopensc/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,28 @@ void sc_format_apdu_cse_lc_le(struct sc_apdu *apdu)
{
/* TODO calculating the APDU case, Lc and Le should actually only be
* done in sc_apdu2bytes, but to gradually change OpenSC we start here. */
/* Let sc_detect_apdu_cse set short or extended and test for chaining */

if (!apdu)
return;
if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
/* extended length */
if (apdu->datalen < SC_MAX_EXT_APDU_DATA_SIZE)
/* extended length or data chaining and/or get response */
if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
apdu->lc = apdu->datalen;
if (apdu->resplen < SC_MAX_EXT_APDU_RESP_SIZE)
if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
apdu->le = apdu->resplen;
if (apdu->resplen && !apdu->datalen)
apdu->cse = SC_APDU_CASE_2_EXT;
apdu->cse = SC_APDU_CASE_2;
if (!apdu->resplen && apdu->datalen)
apdu->cse = SC_APDU_CASE_3_EXT;
apdu->cse = SC_APDU_CASE_3;
if (apdu->resplen && apdu->datalen)
apdu->cse = SC_APDU_CASE_4_EXT;
apdu->cse = SC_APDU_CASE_4;
} else {
/* short length */
if (apdu->datalen < SC_MAX_APDU_DATA_SIZE)
if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
apdu->lc = apdu->datalen;
if (apdu->resplen < SC_MAX_APDU_RESP_SIZE)
if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
apdu->le = apdu->resplen;
if (!apdu->resplen && !apdu->datalen)
apdu->cse = SC_APDU_CASE_1;
Expand Down

0 comments on commit 3b632e6

Please sign in to comment.