coolkey: Do not interpret empty answers as success

Thanks to oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18868
This commit is contained in:
Jakub Jelen 2019-11-11 13:54:26 +01:00 committed by Frank Morgner
parent e6a24b71ab
commit ef3e223917
1 changed files with 22 additions and 16 deletions

View File

@ -1052,30 +1052,36 @@ coolkey_get_life_cycle(sc_card_t *card, coolkey_life_cycle_t *life_cycle)
{
coolkey_status_t status;
u8 *receive_buf;
size_t len;
int r;
size_t receive_len;
int len;
len = sizeof(*life_cycle);
receive_len = sizeof(*life_cycle);
receive_buf = (u8 *)life_cycle;
r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
NULL, 0, &receive_buf, &len, NULL, 0);
if (r == sizeof(*life_cycle)) {
len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
NULL, 0, &receive_buf, &receive_len, NULL, 0);
if (len == sizeof(*life_cycle)) {
return SC_SUCCESS;
}
len = 1;
receive_len = 1;
receive_buf = &life_cycle->life_cycle;
r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
NULL, 0, &receive_buf, &len, NULL, 0);
if (r < 0) {
return r;
len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
NULL, 0, &receive_buf, &receive_len, NULL, 0);
if (len < 0) { /* Error from the trasmittion */
return len;
}
len = sizeof(status);
if (len != 1) { /* The returned data is invalid */
return SC_ERROR_INTERNAL;
}
receive_len = sizeof(status);
receive_buf = (u8 *)&status;
r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
NULL, 0, &receive_buf, &len, NULL, 0);
if (r < 0) {
return r;
len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
NULL, 0, &receive_buf, &receive_len, NULL, 0);
if (len < 0) { /* Error from the trasmittion */
return len;
}
if (len != sizeof(status)) { /* The returned data is invalid */
return SC_ERROR_INTERNAL;
}
life_cycle->protocol_version_major = status.protocol_version_major;
life_cycle->protocol_version_minor = status.protocol_version_minor;