[pkg-opensc-commit] [libp11] 198/239: Any size cert

Eric Dorland eric at moszumanska.debian.org
Sat Oct 17 06:21:33 UTC 2015


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

eric pushed a commit to branch master
in repository libp11.

commit 5853cc9b871247344ae55c6c867fe0dde873650c
Author: Doug Engert <deengert at gmail.com>
Date:   Thu Jul 9 16:57:08 2015 -0500

    Any size cert
    
    Get the cert attribute length, then allocate buffer
---
 src/p11_cert.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/p11_cert.c b/src/p11_cert.c
index 676fd14..1970c8d 100644
--- a/src/p11_cert.c
+++ b/src/p11_cert.c
@@ -136,7 +136,8 @@ static int pkcs11_init_cert(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
 	PKCS11_TOKEN_private *tpriv;
 	PKCS11_CERT_private *kpriv;
 	PKCS11_CERT *cert, *tmp;
-	char label[256], data[4096];
+	char label[256];
+	unsigned char *data;
 	unsigned char id[256];
 	CK_CERTIFICATE_TYPE cert_type;
 	size_t size;
@@ -170,11 +171,16 @@ static int pkcs11_init_cert(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
 
 	if (!pkcs11_getattr_s(token, obj, CKA_LABEL, label, sizeof(label)))
 		cert->label = BUF_strdup(label);
-	size = sizeof(data);
-	if (!pkcs11_getattr_var(token, obj, CKA_VALUE, data, &size)) {
-		const unsigned char *p = (unsigned char *) data;
+	size = 0;
+	if (!pkcs11_getattr_var(token, obj, CKA_VALUE, NULL, &size) && size > 0) {
+		data = (unsigned char *) malloc(size);
+		if (data && !pkcs11_getattr_var(token, obj, CKA_VALUE, data, &size)) {
+			const unsigned char *p = data;
 
-		cert->x509 = d2i_X509(NULL, &p, size);
+			cert->x509 = d2i_X509(NULL, &p, size);
+		}
+		if (data)
+			free(data);
 	}
 	cert->id_len = sizeof(id);
 	if (!pkcs11_getattr_var(token, obj, CKA_ID, id, &cert->id_len)) {

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



More information about the pkg-opensc-commit mailing list