summaryrefslogtreecommitdiff
path: root/authfile.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 /authfile.c
parent5f41f030e2feb5295657285aa8c6602c7810bc4b (diff)
upstream commit
make private key loading functions consistently handle NULL key pointer arguments; ok markus@ Upstream-ID: 92038726ef4a338169c35dacc9c5a07fcc7fa761
Diffstat (limited to 'authfile.c')
-rw-r--r--authfile.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/authfile.c b/authfile.c
index d67042411..f46b4e37f 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfile.c,v 1.120 2015/12/11 04:21:11 mmcc Exp $ */ 1/* $OpenBSD: authfile.c,v 1.121 2016/04/09 12:39:30 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
4 * 4 *
@@ -147,7 +147,8 @@ sshkey_load_public_rsa1(int fd, struct sshkey **keyp, char **commentp)
147 struct sshbuf *b = NULL; 147 struct sshbuf *b = NULL;
148 int r; 148 int r;
149 149
150 *keyp = NULL; 150 if (keyp != NULL)
151 *keyp = NULL;
151 if (commentp != NULL) 152 if (commentp != NULL)
152 *commentp = NULL; 153 *commentp = NULL;
153 154
@@ -200,7 +201,8 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase,
200{ 201{
201 int fd, r; 202 int fd, r;
202 203
203 *keyp = NULL; 204 if (keyp != NULL)
205 *keyp = NULL;
204 if (commentp != NULL) 206 if (commentp != NULL)
205 *commentp = NULL; 207 *commentp = NULL;
206 208
@@ -231,6 +233,8 @@ sshkey_load_private_type_fd(int fd, int type, const char *passphrase,
231 struct sshbuf *buffer = NULL; 233 struct sshbuf *buffer = NULL;
232 int r; 234 int r;
233 235
236 if (keyp != NULL)
237 *keyp = NULL;
234 if ((buffer = sshbuf_new()) == NULL) { 238 if ((buffer = sshbuf_new()) == NULL) {
235 r = SSH_ERR_ALLOC_FAIL; 239 r = SSH_ERR_ALLOC_FAIL;
236 goto out; 240 goto out;
@@ -255,7 +259,8 @@ sshkey_load_private(const char *filename, const char *passphrase,
255 struct sshbuf *buffer = NULL; 259 struct sshbuf *buffer = NULL;
256 int r, fd; 260 int r, fd;
257 261
258 *keyp = NULL; 262 if (keyp != NULL)
263 *keyp = NULL;
259 if (commentp != NULL) 264 if (commentp != NULL)
260 *commentp = NULL; 265 *commentp = NULL;
261 266
@@ -408,7 +413,8 @@ sshkey_load_cert(const char *filename, struct sshkey **keyp)
408 char *file = NULL; 413 char *file = NULL;
409 int r = SSH_ERR_INTERNAL_ERROR; 414 int r = SSH_ERR_INTERNAL_ERROR;
410 415
411 *keyp = NULL; 416 if (keyp != NULL)
417 *keyp = NULL;
412 418
413 if (asprintf(&file, "%s-cert.pub", filename) == -1) 419 if (asprintf(&file, "%s-cert.pub", filename) == -1)
414 return SSH_ERR_ALLOC_FAIL; 420 return SSH_ERR_ALLOC_FAIL;
@@ -418,11 +424,12 @@ sshkey_load_cert(const char *filename, struct sshkey **keyp)
418 } 424 }
419 if ((r = sshkey_try_load_public(pub, file, NULL)) != 0) 425 if ((r = sshkey_try_load_public(pub, file, NULL)) != 0)
420 goto out; 426 goto out;
421 427 /* success */
422 *keyp = pub; 428 if (keyp != NULL) {
423 pub = NULL; 429 *keyp = pub;
430 pub = NULL;
431 }
424 r = 0; 432 r = 0;
425
426 out: 433 out:
427 free(file); 434 free(file);
428 sshkey_free(pub); 435 sshkey_free(pub);
@@ -437,7 +444,8 @@ sshkey_load_private_cert(int type, const char *filename, const char *passphrase,
437 struct sshkey *key = NULL, *cert = NULL; 444 struct sshkey *key = NULL, *cert = NULL;
438 int r; 445 int r;
439 446
440 *keyp = NULL; 447 if (keyp != NULL)
448 *keyp = NULL;
441 449
442 switch (type) { 450 switch (type) {
443#ifdef WITH_OPENSSL 451#ifdef WITH_OPENSSL
@@ -467,8 +475,10 @@ sshkey_load_private_cert(int type, const char *filename, const char *passphrase,
467 (r = sshkey_cert_copy(cert, key)) != 0) 475 (r = sshkey_cert_copy(cert, key)) != 0)
468 goto out; 476 goto out;
469 r = 0; 477 r = 0;
470 *keyp = key; 478 if (keyp != NULL) {
471 key = NULL; 479 *keyp = key;
480 key = NULL;
481 }
472 out: 482 out:
473 sshkey_free(key); 483 sshkey_free(key);
474 sshkey_free(cert); 484 sshkey_free(cert);