[pkg-opensc-commit] [opensc] 289/295: fixed Coverity issues

Eric Dorland eric at moszumanska.debian.org
Sat Jun 24 21:11:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 4c654606eacb1fc059bb4f027e3c94e45c273495
Author: Frank Morgner <frankmorgner at gmail.com>
Date:   Tue Jun 13 13:04:51 2017 +0200

    fixed Coverity issues
    
    Fixes https://github.com/OpenSC/OpenSC/issues/1057
---
 src/libopensc/pkcs15-cache.c  | 21 ++++++++++++---------
 src/libopensc/pkcs15-pubkey.c |  7 +++++--
 src/pkcs11/framework-pkcs15.c |  3 +++
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/libopensc/pkcs15-cache.c b/src/libopensc/pkcs15-cache.c
index 824f1d1..1659393 100644
--- a/src/libopensc/pkcs15-cache.c
+++ b/src/libopensc/pkcs15-cache.c
@@ -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;
diff --git a/src/libopensc/pkcs15-pubkey.c b/src/libopensc/pkcs15-pubkey.c
index 5e6bfb9..e1935a1 100644
--- a/src/libopensc/pkcs15-pubkey.c
+++ b/src/libopensc/pkcs15-pubkey.c
@@ -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);
 
diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c
index 8a4f09b..776f466 100644
--- a/src/pkcs11/framework-pkcs15.c
+++ b/src/pkcs11/framework-pkcs15.c
@@ -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 */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list