Skip to content

Commit

Permalink
fixed Coverity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Jun 13, 2017
1 parent e894bd1 commit 4c65460
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/libopensc/pkcs15-cache.c
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/libopensc/pkcs15-pubkey.c
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/pkcs11/framework-pkcs15.c
Expand Up @@ -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 */
Expand Down

0 comments on commit 4c65460

Please sign in to comment.