Index: apdu.c =================================================================== --- apdu.c (revision 4706) +++ apdu.c (working copy) @@ -337,14 +337,13 @@ error: sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Invalid Case %d %s APDU:\n" "cse=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%lu le=%lu\n" - "resp=%p resplen=%lu data=%p datalen=%lu max_send_size:%lu max_recv_size:%lu", + "resp=%p resplen=%lu data=%p datalen=%lu", apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short", apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2, (unsigned long) apdu->lc, (unsigned long) apdu->le, apdu->resp, (unsigned long) apdu->resplen, - apdu->data, (unsigned long) apdu->datalen, - card->max_recv_size, card->max_send_size); + apdu->data, (unsigned long) apdu->datalen); return SC_ERROR_INVALID_ARGUMENTS; } @@ -487,12 +486,18 @@ SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r); if (buflen < le) - return SC_ERROR_WRONG_LENGTH; + /* copy as much as will fit in requested buffer */ + le = buflen; memcpy(buf, tbuf, le); buf += le; buflen -= le; + /* we have all the data the caller requested + * even if the card has more data */ + if (buflen == 0) + break; + minlen -= le; if (r != 0) le = minlen = (size_t)r;