mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-27 07:44:29 +02:00
upstream commit
make private key loading functions consistently handle NULL key pointer arguments; ok markus@ Upstream-ID: 92038726ef4a338169c35dacc9c5a07fcc7fa761
This commit is contained in:
parent
5f41f030e2
commit
dce19bf6e4
34
authfile.c
34
authfile.c
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: authfile.c,v 1.120 2015/12/11 04:21:11 mmcc Exp $ */
|
/* $OpenBSD: authfile.c,v 1.121 2016/04/09 12:39:30 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
|
* Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -147,7 +147,8 @@ sshkey_load_public_rsa1(int fd, struct sshkey **keyp, char **commentp)
|
|||||||
struct sshbuf *b = NULL;
|
struct sshbuf *b = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if (commentp != NULL)
|
if (commentp != NULL)
|
||||||
*commentp = NULL;
|
*commentp = NULL;
|
||||||
|
|
||||||
@ -200,7 +201,8 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase,
|
|||||||
{
|
{
|
||||||
int fd, r;
|
int fd, r;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if (commentp != NULL)
|
if (commentp != NULL)
|
||||||
*commentp = NULL;
|
*commentp = NULL;
|
||||||
|
|
||||||
@ -231,6 +233,8 @@ sshkey_load_private_type_fd(int fd, int type, const char *passphrase,
|
|||||||
struct sshbuf *buffer = NULL;
|
struct sshbuf *buffer = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if ((buffer = sshbuf_new()) == NULL) {
|
if ((buffer = sshbuf_new()) == NULL) {
|
||||||
r = SSH_ERR_ALLOC_FAIL;
|
r = SSH_ERR_ALLOC_FAIL;
|
||||||
goto out;
|
goto out;
|
||||||
@ -255,7 +259,8 @@ sshkey_load_private(const char *filename, const char *passphrase,
|
|||||||
struct sshbuf *buffer = NULL;
|
struct sshbuf *buffer = NULL;
|
||||||
int r, fd;
|
int r, fd;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if (commentp != NULL)
|
if (commentp != NULL)
|
||||||
*commentp = NULL;
|
*commentp = NULL;
|
||||||
|
|
||||||
@ -408,7 +413,8 @@ sshkey_load_cert(const char *filename, struct sshkey **keyp)
|
|||||||
char *file = NULL;
|
char *file = NULL;
|
||||||
int r = SSH_ERR_INTERNAL_ERROR;
|
int r = SSH_ERR_INTERNAL_ERROR;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
|
|
||||||
if (asprintf(&file, "%s-cert.pub", filename) == -1)
|
if (asprintf(&file, "%s-cert.pub", filename) == -1)
|
||||||
return SSH_ERR_ALLOC_FAIL;
|
return SSH_ERR_ALLOC_FAIL;
|
||||||
@ -418,11 +424,12 @@ sshkey_load_cert(const char *filename, struct sshkey **keyp)
|
|||||||
}
|
}
|
||||||
if ((r = sshkey_try_load_public(pub, file, NULL)) != 0)
|
if ((r = sshkey_try_load_public(pub, file, NULL)) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
/* success */
|
||||||
*keyp = pub;
|
if (keyp != NULL) {
|
||||||
pub = NULL;
|
*keyp = pub;
|
||||||
|
pub = NULL;
|
||||||
|
}
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(file);
|
free(file);
|
||||||
sshkey_free(pub);
|
sshkey_free(pub);
|
||||||
@ -437,7 +444,8 @@ sshkey_load_private_cert(int type, const char *filename, const char *passphrase,
|
|||||||
struct sshkey *key = NULL, *cert = NULL;
|
struct sshkey *key = NULL, *cert = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
#ifdef WITH_OPENSSL
|
#ifdef WITH_OPENSSL
|
||||||
@ -467,8 +475,10 @@ sshkey_load_private_cert(int type, const char *filename, const char *passphrase,
|
|||||||
(r = sshkey_cert_copy(cert, key)) != 0)
|
(r = sshkey_cert_copy(cert, key)) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
r = 0;
|
r = 0;
|
||||||
*keyp = key;
|
if (keyp != NULL) {
|
||||||
key = NULL;
|
*keyp = key;
|
||||||
|
key = NULL;
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
sshkey_free(key);
|
sshkey_free(key);
|
||||||
sshkey_free(cert);
|
sshkey_free(cert);
|
||||||
|
40
sshkey.c
40
sshkey.c
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: sshkey.c,v 1.31 2015/12/11 04:21:12 mmcc Exp $ */
|
/* $OpenBSD: sshkey.c,v 1.32 2016/04/09 12:39:30 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
|
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
|
||||||
* Copyright (c) 2008 Alexander von Gernler. All rights reserved.
|
* Copyright (c) 2008 Alexander von Gernler. All rights reserved.
|
||||||
@ -1966,7 +1966,8 @@ sshkey_from_blob_internal(struct sshbuf *b, struct sshkey **keyp,
|
|||||||
#ifdef DEBUG_PK /* XXX */
|
#ifdef DEBUG_PK /* XXX */
|
||||||
sshbuf_dump(b, stderr);
|
sshbuf_dump(b, stderr);
|
||||||
#endif
|
#endif
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if ((copy = sshbuf_fromb(b)) == NULL) {
|
if ((copy = sshbuf_fromb(b)) == NULL) {
|
||||||
ret = SSH_ERR_ALLOC_FAIL;
|
ret = SSH_ERR_ALLOC_FAIL;
|
||||||
goto out;
|
goto out;
|
||||||
@ -2121,8 +2122,10 @@ sshkey_from_blob_internal(struct sshbuf *b, struct sshkey **keyp,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
*keyp = key;
|
if (keyp != NULL) {
|
||||||
key = NULL;
|
*keyp = key;
|
||||||
|
key = NULL;
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
sshbuf_free(copy);
|
sshbuf_free(copy);
|
||||||
sshkey_free(key);
|
sshkey_free(key);
|
||||||
@ -3631,12 +3634,10 @@ sshkey_parse_public_rsa1_fileblob(struct sshbuf *blob,
|
|||||||
/* The encrypted private part is not parsed by this function. */
|
/* The encrypted private part is not parsed by this function. */
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
if (keyp != NULL)
|
if (keyp != NULL) {
|
||||||
*keyp = pub;
|
*keyp = pub;
|
||||||
else
|
pub = NULL;
|
||||||
sshkey_free(pub);
|
}
|
||||||
pub = NULL;
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
sshbuf_free(copy);
|
sshbuf_free(copy);
|
||||||
sshkey_free(pub);
|
sshkey_free(pub);
|
||||||
@ -3657,7 +3658,8 @@ sshkey_parse_private_rsa1(struct sshbuf *blob, const char *passphrase,
|
|||||||
const struct sshcipher *cipher;
|
const struct sshcipher *cipher;
|
||||||
struct sshkey *prv = NULL;
|
struct sshkey *prv = NULL;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if (commentp != NULL)
|
if (commentp != NULL)
|
||||||
*commentp = NULL;
|
*commentp = NULL;
|
||||||
|
|
||||||
@ -3743,8 +3745,10 @@ sshkey_parse_private_rsa1(struct sshbuf *blob, const char *passphrase,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
r = 0;
|
r = 0;
|
||||||
*keyp = prv;
|
if (keyp != NULL) {
|
||||||
prv = NULL;
|
*keyp = prv;
|
||||||
|
prv = NULL;
|
||||||
|
}
|
||||||
if (commentp != NULL) {
|
if (commentp != NULL) {
|
||||||
*commentp = comment;
|
*commentp = comment;
|
||||||
comment = NULL;
|
comment = NULL;
|
||||||
@ -3769,7 +3773,8 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type,
|
|||||||
BIO *bio = NULL;
|
BIO *bio = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
|
|
||||||
if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX)
|
if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX)
|
||||||
return SSH_ERR_ALLOC_FAIL;
|
return SSH_ERR_ALLOC_FAIL;
|
||||||
@ -3838,8 +3843,10 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
r = 0;
|
r = 0;
|
||||||
*keyp = prv;
|
if (keyp != NULL) {
|
||||||
prv = NULL;
|
*keyp = prv;
|
||||||
|
prv = NULL;
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
if (pk != NULL)
|
if (pk != NULL)
|
||||||
@ -3853,7 +3860,8 @@ int
|
|||||||
sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
|
sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
|
||||||
const char *passphrase, struct sshkey **keyp, char **commentp)
|
const char *passphrase, struct sshkey **keyp, char **commentp)
|
||||||
{
|
{
|
||||||
*keyp = NULL;
|
if (keyp != NULL)
|
||||||
|
*keyp = NULL;
|
||||||
if (commentp != NULL)
|
if (commentp != NULL)
|
||||||
*commentp = NULL;
|
*commentp = NULL;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user