fixed Coverity issues

Fixes https://github.com/OpenSC/OpenSC/issues/1057
This commit is contained in:
Frank Morgner 2017-06-13 13:04:51 +02:00
parent e894bd175b
commit 4c654606ea
3 changed files with 20 additions and 11 deletions

View File

@ -156,26 +156,29 @@ int sc_pkcs15_read_cached_file(struct sc_pkcs15_card *p15card,
goto err;
}
}
else if (count > *bufsize) {
rv = SC_ERROR_BUFFER_TOO_SMALL;
goto err;
else {
if (count > *bufsize) {
rv = SC_ERROR_BUFFER_TOO_SMALL;
goto err;
}
data = *buf;
}
if (data)
*buf = data;
if (count != fread(*buf, 1, count, f)) {
if (count != fread(data, 1, count, f)) {
rv = SC_ERROR_BUFFER_TOO_SMALL;
goto err;
}
*buf = data;
*bufsize = count;
rv = SC_SUCCESS;
err:
if (rv != SC_SUCCESS)
if (data)
if (rv != SC_SUCCESS) {
if (data != *buf) {
free(data);
}
}
fclose(f);
return rv;

View File

@ -903,16 +903,19 @@ int
sc_pkcs15_read_pubkey(struct sc_pkcs15_card *p15card, const struct sc_pkcs15_object *obj,
struct sc_pkcs15_pubkey **out)
{
struct sc_context *ctx = p15card->card->ctx;
struct sc_context *ctx;
const struct sc_pkcs15_pubkey_info *info = NULL;
struct sc_pkcs15_pubkey *pubkey = NULL;
unsigned char *data = NULL;
size_t len;
int algorithm, r;
if (p15card == NULL || obj == NULL || out == NULL) {
if (p15card == NULL || p15card->card == NULL || p15card->card->ops == NULL
|| obj == NULL || out == NULL) {
return SC_ERROR_INVALID_ARGUMENTS;
}
ctx = p15card->card->ctx;
LOG_FUNC_CALLED(ctx);
sc_log(ctx, "Public key type 0x%X", obj->type);

View File

@ -590,6 +590,9 @@ public_key_created(struct pkcs15_fw_data *fw_data, const struct sc_pkcs15_id *id
static void
pkcs15_cert_extract_label(struct pkcs15_cert_object *cert)
{
if (!cert || !cert->cert_p15obj || !cert->cert_data)
return;
sc_log(context, "pkcs15_cert_extract_label() called. Current label: %s", cert->cert_p15obj->label);
/* if we didn't get a label, set one based on the CN */