cac: Avoid signed/unsigned casting reported by coverity

src/libopensc/card-cac.c:1707: negative_returns: "val_len" is passed to a parameter that cannot be negative.
This commit is contained in:
Jakub Jelen 2019-04-23 12:27:03 +02:00 committed by Frank Morgner
parent abc6cfbe68
commit 13429baed0
1 changed files with 4 additions and 4 deletions

View File

@ -1664,7 +1664,6 @@ static int cac_populate_cac_alt(sc_card_t *card, int index, cac_private_data_t *
cac_object_t pki_obj = cac_cac_pki_obj;
u8 buf[100];
u8 *val;
size_t val_len;
/* populate PKI objects */
for (i = index; i < MAX_CAC_SLOTS; i++) {
@ -1701,13 +1700,14 @@ static int cac_populate_cac_alt(sc_card_t *card, int index, cac_private_data_t *
return r; /* shouldn't happen unless the card has been removed or is malfunctioning */
}
val = buf;
val_len = cac_read_binary(card, 0, val, sizeof(buf), 0);
if (val_len > 0) {
r = cac_read_binary(card, 0, val, sizeof(buf), 0);
if (r > 0) {
#ifdef ENABLE_OPENSSL
size_t val_len = r;
priv->cac_id = malloc(20);
if (priv->cac_id == NULL) {
return SC_ERROR_OUT_OF_MEMORY;
}
#ifdef ENABLE_OPENSSL
SHA1(val, val_len, priv->cac_id);
priv->cac_id_len = 20;
sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,