summaryrefslogtreecommitdiff
path: root/ssh-pkcs11.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2021-11-18 21:11:01 +0000
committerDamien Miller <djm@mindrot.org>2021-11-19 08:12:57 +1100
commit97f9b6e61316c97a32dad94b7a37daa9b5f6b836 (patch)
treee16ec6a78ab0c51d1bb3f9d0d0160d0668cb5964 /ssh-pkcs11.c
parentc74aa0eb73bd1edf79947d92d9c618fc3424c4a6 (diff)
downloadopenssh-git-97f9b6e61316c97a32dad94b7a37daa9b5f6b836.tar.gz
upstream: avoid xmalloc(0) for PKCS#11 keyid for ECDSA keys (we
already did this for RSA keys). Avoids fatal errors for PKCS#11 libraries that return empty keyid, e.g. Microchip ATECC608B "cryptoauthlib"; bz#3364 OpenBSD-Commit-ID: 054d4dc1d6a99a2e6f8eebc48207b534057c154d
Diffstat (limited to 'ssh-pkcs11.c')
-rw-r--r--ssh-pkcs11.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
index 649a6d3b..b2e2b32a 100644
--- a/ssh-pkcs11.c
+++ b/ssh-pkcs11.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-pkcs11.c,v 1.54 2021/08/11 05:20:17 djm Exp $ */
+/* $OpenBSD: ssh-pkcs11.c,v 1.55 2021/11/18 21:11:01 djm Exp $ */
/*
* Copyright (c) 2010 Markus Friedl. All rights reserved.
* Copyright (c) 2014 Pedro Martelletto. All rights reserved.
@@ -611,9 +611,10 @@ pkcs11_ecdsa_wrap(struct pkcs11_provider *provider, CK_ULONG slotidx,
k11->slotidx = slotidx;
/* identify key object on smartcard */
k11->keyid_len = keyid_attrib->ulValueLen;
- k11->keyid = xmalloc(k11->keyid_len);
- memcpy(k11->keyid, keyid_attrib->pValue, k11->keyid_len);
-
+ if (k11->keyid_len > 0) {
+ k11->keyid = xmalloc(k11->keyid_len);
+ memcpy(k11->keyid, keyid_attrib->pValue, k11->keyid_len);
+ }
EC_KEY_set_method(ec, ec_key_method);
EC_KEY_set_ex_data(ec, ec_key_idx, k11);