Always allocate resp buffer in DNIe.
This commit is contained in:
parent
19df418fb6
commit
20b1d829b9
|
@ -760,15 +760,23 @@ static int dnie_sm_free_wrapped_apdu(struct sc_card *card,
|
||||||
|
|
||||||
if ((*sm_apdu) != plain) {
|
if ((*sm_apdu) != plain) {
|
||||||
rv = cwa_decode_response(card, provider, *sm_apdu);
|
rv = cwa_decode_response(card, provider, *sm_apdu);
|
||||||
if (plain) {
|
if (plain && rv == SC_SUCCESS) {
|
||||||
|
if (plain->resp) {
|
||||||
|
/* copy the response into the original resp buffer */
|
||||||
|
if ((*sm_apdu)->resplen <= plain->resplen) {
|
||||||
|
memcpy(plain->resp, (*sm_apdu)->resp, (*sm_apdu)->resplen);
|
||||||
plain->resplen = (*sm_apdu)->resplen;
|
plain->resplen = (*sm_apdu)->resplen;
|
||||||
|
} else {
|
||||||
|
sc_log(card->ctx, "Invalid initial length, needed %lu bytes but has %lu",
|
||||||
|
(*sm_apdu)->resplen, plain->resplen);
|
||||||
|
rv = SC_ERROR_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
}
|
||||||
plain->sw1 = (*sm_apdu)->sw1;
|
plain->sw1 = (*sm_apdu)->sw1;
|
||||||
plain->sw2 = (*sm_apdu)->sw2;
|
plain->sw2 = (*sm_apdu)->sw2;
|
||||||
if (((*sm_apdu)->data) != plain->data)
|
|
||||||
free((unsigned char *) (*sm_apdu)->data);
|
|
||||||
if ((*sm_apdu)->resp != plain->resp)
|
|
||||||
free((*sm_apdu)->resp);
|
|
||||||
}
|
}
|
||||||
|
free((unsigned char *) (*sm_apdu)->data);
|
||||||
|
free((*sm_apdu)->resp);
|
||||||
free(*sm_apdu);
|
free(*sm_apdu);
|
||||||
}
|
}
|
||||||
*sm_apdu = NULL;
|
*sm_apdu = NULL;
|
||||||
|
|
|
@ -1431,11 +1431,9 @@ int cwa_encode_apdu(sc_card_t * card,
|
||||||
sizeof(u8));
|
sizeof(u8));
|
||||||
ccbuf = calloc(MAX(SC_MAX_APDU_BUFFER_SIZE, 20 + from->datalen),
|
ccbuf = calloc(MAX(SC_MAX_APDU_BUFFER_SIZE, 20 + from->datalen),
|
||||||
sizeof(u8));
|
sizeof(u8));
|
||||||
if (!to->resp) {
|
/* always create a new buffer for the encoded response */
|
||||||
/* if no response create a buffer for the encoded response */
|
|
||||||
to->resp = calloc(MAX_RESP_BUFFER_SIZE, sizeof(u8));
|
to->resp = calloc(MAX_RESP_BUFFER_SIZE, sizeof(u8));
|
||||||
to->resplen = MAX_RESP_BUFFER_SIZE;
|
to->resplen = MAX_RESP_BUFFER_SIZE;
|
||||||
}
|
|
||||||
if (!apdubuf || !ccbuf || (!from->resp && !to->resp)) {
|
if (!apdubuf || !ccbuf || (!from->resp && !to->resp)) {
|
||||||
res = SC_ERROR_OUT_OF_MEMORY;
|
res = SC_ERROR_OUT_OF_MEMORY;
|
||||||
goto err;
|
goto err;
|
||||||
|
|
Loading…
Reference in New Issue