summaryrefslogtreecommitdiff
path: root/sshkey.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2016-04-09 12:39:30 +0000
committerDamien Miller <djm@mindrot.org>2016-04-13 10:44:06 +1000
commitdce19bf6e4a2a3d0b13a81224de63fc316461ab9 (patch)
treeb97a0ac4f71bf5c6d5a6e35bd11396cf02dcd70a /sshkey.c
parent5f41f030e2feb5295657285aa8c6602c7810bc4b (diff)
upstream commit
make private key loading functions consistently handle NULL key pointer arguments; ok markus@ Upstream-ID: 92038726ef4a338169c35dacc9c5a07fcc7fa761
Diffstat (limited to 'sshkey.c')
-rw-r--r--sshkey.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/sshkey.c b/sshkey.c
index 87b093e91..2ce7ada9f 100644
--- a/sshkey.c
+++ b/sshkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshkey.c,v 1.31 2015/12/11 04:21:12 mmcc Exp $ */ 1/* $OpenBSD: sshkey.c,v 1.32 2016/04/09 12:39:30 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Alexander von Gernler. All rights reserved. 4 * Copyright (c) 2008 Alexander von Gernler. All rights reserved.
@@ -1966,7 +1966,8 @@ sshkey_from_blob_internal(struct sshbuf *b, struct sshkey **keyp,
1966#ifdef DEBUG_PK /* XXX */ 1966#ifdef DEBUG_PK /* XXX */
1967 sshbuf_dump(b, stderr); 1967 sshbuf_dump(b, stderr);
1968#endif 1968#endif
1969 *keyp = NULL; 1969 if (keyp != NULL)
1970 *keyp = NULL;
1970 if ((copy = sshbuf_fromb(b)) == NULL) { 1971 if ((copy = sshbuf_fromb(b)) == NULL) {
1971 ret = SSH_ERR_ALLOC_FAIL; 1972 ret = SSH_ERR_ALLOC_FAIL;
1972 goto out; 1973 goto out;
@@ -2121,8 +2122,10 @@ sshkey_from_blob_internal(struct sshbuf *b, struct sshkey **keyp,
2121 goto out; 2122 goto out;
2122 } 2123 }
2123 ret = 0; 2124 ret = 0;
2124 *keyp = key; 2125 if (keyp != NULL) {
2125 key = NULL; 2126 *keyp = key;
2127 key = NULL;
2128 }
2126 out: 2129 out:
2127 sshbuf_free(copy); 2130 sshbuf_free(copy);
2128 sshkey_free(key); 2131 sshkey_free(key);
@@ -3631,12 +3634,10 @@ sshkey_parse_public_rsa1_fileblob(struct sshbuf *blob,
3631 /* The encrypted private part is not parsed by this function. */ 3634 /* The encrypted private part is not parsed by this function. */
3632 3635
3633 r = 0; 3636 r = 0;
3634 if (keyp != NULL) 3637 if (keyp != NULL) {
3635 *keyp = pub; 3638 *keyp = pub;
3636 else 3639 pub = NULL;
3637 sshkey_free(pub); 3640 }
3638 pub = NULL;
3639
3640 out: 3641 out:
3641 sshbuf_free(copy); 3642 sshbuf_free(copy);
3642 sshkey_free(pub); 3643 sshkey_free(pub);
@@ -3657,7 +3658,8 @@ sshkey_parse_private_rsa1(struct sshbuf *blob, const char *passphrase,
3657 const struct sshcipher *cipher; 3658 const struct sshcipher *cipher;
3658 struct sshkey *prv = NULL; 3659 struct sshkey *prv = NULL;
3659 3660
3660 *keyp = NULL; 3661 if (keyp != NULL)
3662 *keyp = NULL;
3661 if (commentp != NULL) 3663 if (commentp != NULL)
3662 *commentp = NULL; 3664 *commentp = NULL;
3663 3665
@@ -3743,8 +3745,10 @@ sshkey_parse_private_rsa1(struct sshbuf *blob, const char *passphrase,
3743 goto out; 3745 goto out;
3744 } 3746 }
3745 r = 0; 3747 r = 0;
3746 *keyp = prv; 3748 if (keyp != NULL) {
3747 prv = NULL; 3749 *keyp = prv;
3750 prv = NULL;
3751 }
3748 if (commentp != NULL) { 3752 if (commentp != NULL) {
3749 *commentp = comment; 3753 *commentp = comment;
3750 comment = NULL; 3754 comment = NULL;
@@ -3769,7 +3773,8 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type,
3769 BIO *bio = NULL; 3773 BIO *bio = NULL;
3770 int r; 3774 int r;
3771 3775
3772 *keyp = NULL; 3776 if (keyp != NULL)
3777 *keyp = NULL;
3773 3778
3774 if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX) 3779 if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX)
3775 return SSH_ERR_ALLOC_FAIL; 3780 return SSH_ERR_ALLOC_FAIL;
@@ -3838,8 +3843,10 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type,
3838 goto out; 3843 goto out;
3839 } 3844 }
3840 r = 0; 3845 r = 0;
3841 *keyp = prv; 3846 if (keyp != NULL) {
3842 prv = NULL; 3847 *keyp = prv;
3848 prv = NULL;
3849 }
3843 out: 3850 out:
3844 BIO_free(bio); 3851 BIO_free(bio);
3845 if (pk != NULL) 3852 if (pk != NULL)
@@ -3853,7 +3860,8 @@ int
3853sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type, 3860sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
3854 const char *passphrase, struct sshkey **keyp, char **commentp) 3861 const char *passphrase, struct sshkey **keyp, char **commentp)
3855{ 3862{
3856 *keyp = NULL; 3863 if (keyp != NULL)
3864 *keyp = NULL;
3857 if (commentp != NULL) 3865 if (commentp != NULL)
3858 *commentp = NULL; 3866 *commentp = NULL;
3859 3867