From 5a9d47476591458e69f9dcfb9c2f6a6c8a0db76d Mon Sep 17 00:00:00 2001 From: Ave Date: Tue, 29 Dec 2020 02:15:15 +0300 Subject: [PATCH] emrtd: Better coverity bits for hash verif --- client/src/cmdhfemrtd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/cmdhfemrtd.c b/client/src/cmdhfemrtd.c index 2235dc60b..770fde28f 100644 --- a/client/src/cmdhfemrtd.c +++ b/client/src/cmdhfemrtd.c @@ -1532,16 +1532,15 @@ static int emrtd_ef_sod_extract_signatures(uint8_t *data, size_t datalen, uint8_ return PM3_SUCCESS; } -static int emrtd_parse_ef_sod_hashes(uint8_t *data, size_t datalen, uint8_t *hashes) { +static int emrtd_parse_ef_sod_hashes(uint8_t *data, size_t datalen, uint8_t *hashes, int *hashalgo) { uint8_t emrtdsig[EMRTD_MAX_FILE_SIZE] = { 0x00 }; uint8_t hashlist[EMRTD_MAX_FILE_SIZE] = { 0x00 }; - uint8_t hash[65] = { 0x00 }; + uint8_t hash[64] = { 0x00 }; size_t hashlen = 0; uint8_t hashidstr[4] = { 0x00 }; size_t hashidstrlen = 0; - // size_t emrtdsiglen, e_datalen, e_fieldlen = 0; size_t emrtdsiglen = 0; size_t hashlistlen = 0; size_t e_datalen = 0; @@ -1572,8 +1571,10 @@ static int emrtd_parse_ef_sod_hashes(uint8_t *data, size_t datalen, uint8_t *has case 0x30: emrtd_lds_get_data_by_tag(hashlist + offset + e_fieldlen + 1, e_datalen, hashidstr, &hashidstrlen, 0x02, 0x00, false, false, 0); emrtd_lds_get_data_by_tag(hashlist + offset + e_fieldlen + 1, e_datalen, hash, &hashlen, 0x04, 0x00, false, false, 0); - if (hashlen <= 64) { // TODO: This is for coverity, account for it. + if (hashlen <= 64) { memcpy(hashes + (hashidstr[0] * 64), hash, hashlen); + } else { + PrintAndLogEx(ERR, "error (emrtd_parse_ef_sod_hashes) hashlen out-of-bounds"); } break; }