fixed more coverity issues

This commit is contained in:
Frank Morgner 2017-04-13 12:46:05 +02:00
parent fcc8ea5939
commit 9d15326de1
9 changed files with 30 additions and 26 deletions

View File

@ -117,7 +117,7 @@ static int npa_load_options(sc_context_t *ctx, struct npa_drv_data *drv_data)
if (!fread_to_eof(file,
(unsigned char **) &drv_data->st_dv_certificate,
&drv_data->st_dv_certificate_len))
sc_log(ctx, "Waring: Could not read %s.\n", file);
sc_log(ctx, "Warning: Could not read %s.\n", file);
}
if (!drv_data->st_certificate
@ -126,7 +126,7 @@ static int npa_load_options(sc_context_t *ctx, struct npa_drv_data *drv_data)
if (!fread_to_eof(file,
(unsigned char **) &drv_data->st_certificate,
&drv_data->st_certificate_len))
sc_log(ctx, "Waring: Could not read %s.\n", file);
sc_log(ctx, "Warning: Could not read %s.\n", file);
}
if (!drv_data->st_key
@ -135,7 +135,7 @@ static int npa_load_options(sc_context_t *ctx, struct npa_drv_data *drv_data)
if (!fread_to_eof(file,
(unsigned char **) &drv_data->st_key,
&drv_data->st_key_len))
sc_log(ctx, "Waring: Could not read %s.\n", file);
sc_log(ctx, "Warning: Could not read %s.\n", file);
}
}
@ -684,8 +684,8 @@ static int npa_logout(sc_card_t *card)
* disable SM on the reader. */
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xA4, 0x00, 0x00);
apdu.cla = 0x0C;
sc_transmit_apdu(card, &apdu);
/* ignore result */
if (SC_SUCCESS != sc_transmit_apdu(card, &apdu))
sc_log(card->ctx, "Warning: Could not logout.");
}
return sc_select_file(card, sc_get_mf_path(), NULL);
}

View File

@ -538,11 +538,12 @@ static int sc_hsm_compute_signature(sc_card_t *card,
sc_apdu_t apdu;
u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
sc_hsm_private_data_t *priv;
if (card == NULL || data == NULL || out == NULL) {
return SC_ERROR_INVALID_ARGUMENTS;
}
priv = (sc_hsm_private_data_t *) card->drv_data;
if (priv->env == NULL) {
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
@ -590,12 +591,13 @@ static int sc_hsm_decipher(sc_card_t *card, const u8 * crgram, size_t crgram_len
size_t len;
sc_apdu_t apdu;
u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
sc_hsm_private_data_t *priv;
if (card == NULL || crgram == NULL || out == NULL) {
return SC_ERROR_INVALID_ARGUMENTS;
}
LOG_FUNC_CALLED(card->ctx);
priv = (sc_hsm_private_data_t *) card->drv_data;
sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x62, priv->env->key_ref[0], priv->algorithm);
apdu.cla = 0x80;

View File

@ -526,8 +526,6 @@ static int load_card_drivers(sc_context_t *ctx, struct _sc_ctx_options *opts)
ctx->card_drivers[drv_count] = func();
if (ctx->card_drivers[drv_count] == NULL) {
sc_log(ctx, "Driver '%s' not available.", ent->name);
if (dll)
sc_dlclose(dll);
continue;
}
@ -818,8 +816,8 @@ int sc_context_create(sc_context_t **ctx_out, const sc_context_param_t *parm)
}
}
if (opts.forced_card_driver) {
/* FIXME: check return value? */
sc_set_card_driver(ctx, opts.forced_card_driver);
if (SC_SUCCESS != sc_set_card_driver(ctx, opts.forced_card_driver))
sc_log(ctx, "Warning: Could not load %s.", opts.forced_card_driver);
free(opts.forced_card_driver);
}
del_drvs(&opts);

View File

@ -397,7 +397,8 @@ iso7816_process_fci(struct sc_card *card, struct sc_file *file,
sc_log(ctx, " EF structure: %d", byte & 0x07);
sc_log(ctx, " tag 0x82: 0x%02x", byte);
/* FIXME: check return value? */
sc_file_set_type_attr(file, &byte, 1);
if (SC_SUCCESS != sc_file_set_type_attr(file, &byte, 1))
sc_log(ctx, "Warning: Could not set file attributes");
}
}

View File

@ -2285,15 +2285,16 @@ int
sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, const struct sc_path *in_path,
unsigned char **buf, size_t *buflen)
{
struct sc_context *ctx = p15card->card->ctx;
struct sc_context *ctx;
struct sc_file *file = NULL;
unsigned char *data = NULL;
size_t len = 0, offset = 0;
int r;
if (p15card == NULL || in_path == NULL || buf == NULL) {
if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
return SC_ERROR_INVALID_ARGUMENTS;
}
ctx = p15card->card->ctx;
LOG_FUNC_CALLED(ctx);
sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
@ -2354,7 +2355,6 @@ sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, const struct sc_path *in_pat
if (r == SC_ERROR_RECORD_NOT_FOUND)
break;
if (r < 0) {
free(data);
goto fail_unlock;
}
if (r < 2)
@ -2376,7 +2376,6 @@ sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, const struct sc_path *in_pat
else {
r = sc_read_binary(p15card->card, offset, data, len, 0);
if (r < 0) {
free(data);
goto fail_unlock;
}
/* sc_read_binary may return less than requested */
@ -2395,6 +2394,7 @@ sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, const struct sc_path *in_pat
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
fail_unlock:
free(data);
sc_file_free(file);
sc_unlock(p15card->card);
LOG_FUNC_RETURN(ctx, r);

View File

@ -987,11 +987,11 @@ void sc_detect_escape_cmds(sc_reader_t *reader)
}
}
if (error) {
if (error && reader) {
sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL,
"%d escape command%s failed, need to reset the card",
error, error == 1 ? "" : "s");
if (reader && reader->ops && reader->ops->transmit) {
if (reader->ops && reader->ops->transmit) {
memset(&apdu, 0, sizeof(apdu));
apdu.cse = SC_APDU_CASE_3_SHORT;
apdu.cla = 0x00;

View File

@ -186,12 +186,14 @@ CK_RV push_login_state(struct sc_pkcs11_slot *slot,
goto err;
}
login->pPin = sc_mem_alloc_secure(context, (sizeof *pPin)*ulPinLen);
if (login->pPin == NULL) {
goto err;
if (pPin && ulPinLen) {
login->pPin = sc_mem_alloc_secure(context, (sizeof *pPin)*ulPinLen);
if (login->pPin == NULL) {
goto err;
}
memcpy(login->pPin, pPin, (sizeof *pPin)*ulPinLen);
login->ulPinLen = ulPinLen;
}
memcpy(login->pPin, pPin, (sizeof *pPin)*ulPinLen);
login->ulPinLen = ulPinLen;
login->userType = userType;
if (0 > list_append(&slot->logins, login)) {

View File

@ -1051,7 +1051,7 @@ int perform_pace(sc_card_t *card,
int r;
const unsigned char *pp;
if (!card || !pace_output)
if (!card || !card->reader || !card->reader->ops || !pace_output)
return SC_ERROR_INVALID_ARGUMENTS;
/* show description in advance to give the user more time to read it...
@ -2346,7 +2346,8 @@ int perform_pace(sc_card_t *card,
{
int r;
if (card->reader->capabilities & SC_READER_CAP_PACE_GENERIC
if (card && card->reader
&& card->reader->capabilities & SC_READER_CAP_PACE_GENERIC
&& card->reader->ops->perform_pace) {
r = card->reader->ops->perform_pace(card->reader, &pace_input, pace_output);
} else {

View File

@ -690,7 +690,7 @@ int iso_get_sm_apdu(struct sc_card *card, struct sc_apdu *apdu, struct sc_apdu *
int iso_free_sm_apdu(struct sc_card *card, struct sc_apdu *apdu, struct sc_apdu **sm_apdu)
{
struct sc_apdu *p = *sm_apdu;
struct sc_apdu *p;
int r;
if (!sm_apdu)