summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormmcc@openbsd.org <mmcc@openbsd.org>2015-12-10 17:08:40 +0000
committerDamien Miller <djm@mindrot.org>2015-12-11 13:23:14 +1100
commitd59ce08811bf94111c2f442184cf7d1257ffae24 (patch)
tree5885ad687f762834250c9c3f5b53b3f1b750c9f1
parent8e56dd46cb37879c73bce2d6032cf5e7f82d5a71 (diff)
upstream commit
Remove NULL-checks before free(). ok dtucker@ Upstream-ID: e3d3cb1ce900179906af36517b5eea0fb15e6ef8
-rw-r--r--auth-options.c26
-rw-r--r--authfile.c5
-rw-r--r--cipher.c5
-rw-r--r--kex.c5
-rw-r--r--packet.c14
-rw-r--r--ssh-dss.c5
-rw-r--r--ssh-rsa.c5
-rw-r--r--ssh.c5
-rw-r--r--sshconnect2.c5
-rw-r--r--sshd.c5
-rw-r--r--sshkey.c17
11 files changed, 36 insertions, 61 deletions
diff --git a/auth-options.c b/auth-options.c
index cb68802de..edbaf80bb 100644
--- a/auth-options.c
+++ b/auth-options.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth-options.c,v 1.69 2015/11/16 00:30:02 djm Exp $ */ 1/* $OpenBSD: auth-options.c,v 1.70 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -75,14 +75,10 @@ auth_clear_options(void)
75 free(ce->s); 75 free(ce->s);
76 free(ce); 76 free(ce);
77 } 77 }
78 if (forced_command) { 78 free(forced_command);
79 free(forced_command); 79 forced_command = NULL;
80 forced_command = NULL; 80 free(authorized_principals);
81 } 81 authorized_principals = NULL;
82 if (authorized_principals) {
83 free(authorized_principals);
84 authorized_principals = NULL;
85 }
86 forced_tun_device = -1; 82 forced_tun_device = -1;
87 channel_clear_permitted_opens(); 83 channel_clear_permitted_opens();
88} 84}
@@ -175,8 +171,7 @@ auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
175 cp = "command=\""; 171 cp = "command=\"";
176 if (strncasecmp(opts, cp, strlen(cp)) == 0) { 172 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
177 opts += strlen(cp); 173 opts += strlen(cp);
178 if (forced_command != NULL) 174 free(forced_command);
179 free(forced_command);
180 forced_command = xmalloc(strlen(opts) + 1); 175 forced_command = xmalloc(strlen(opts) + 1);
181 i = 0; 176 i = 0;
182 while (*opts) { 177 while (*opts) {
@@ -206,8 +201,7 @@ auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
206 cp = "principals=\""; 201 cp = "principals=\"";
207 if (strncasecmp(opts, cp, strlen(cp)) == 0) { 202 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
208 opts += strlen(cp); 203 opts += strlen(cp);
209 if (authorized_principals != NULL) 204 free(authorized_principals);
210 free(authorized_principals);
211 authorized_principals = xmalloc(strlen(opts) + 1); 205 authorized_principals = xmalloc(strlen(opts) + 1);
212 i = 0; 206 i = 0;
213 while (*opts) { 207 while (*opts) {
@@ -593,8 +587,7 @@ parse_option_list(struct sshbuf *oblob, struct passwd *pw,
593 free(*cert_forced_command); 587 free(*cert_forced_command);
594 *cert_forced_command = NULL; 588 *cert_forced_command = NULL;
595 } 589 }
596 if (name != NULL) 590 free(name);
597 free(name);
598 sshbuf_free(data); 591 sshbuf_free(data);
599 sshbuf_free(c); 592 sshbuf_free(c);
600 return ret; 593 return ret;
@@ -638,8 +631,7 @@ auth_cert_options(struct sshkey *k, struct passwd *pw)
638 no_user_rc |= cert_no_user_rc; 631 no_user_rc |= cert_no_user_rc;
639 /* CA-specified forced command supersedes key option */ 632 /* CA-specified forced command supersedes key option */
640 if (cert_forced_command != NULL) { 633 if (cert_forced_command != NULL) {
641 if (forced_command != NULL) 634 free(forced_command);
642 free(forced_command);
643 forced_command = cert_forced_command; 635 forced_command = cert_forced_command;
644 } 636 }
645 return 0; 637 return 0;
diff --git a/authfile.c b/authfile.c
index 1907cb1cc..668df7d9e 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfile.c,v 1.117 2015/09/13 14:39:16 tim Exp $ */ 1/* $OpenBSD: authfile.c,v 1.118 2015/12/10 17:08:40 mmcc 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 *
@@ -426,8 +426,7 @@ sshkey_load_cert(const char *filename, struct sshkey **keyp)
426 r = 0; 426 r = 0;
427 427
428 out: 428 out:
429 if (file != NULL) 429 free(file);
430 free(file);
431 if (pub != NULL) 430 if (pub != NULL)
432 sshkey_free(pub); 431 sshkey_free(pub);
433 return r; 432 return r;
diff --git a/cipher.c b/cipher.c
index 02dae6f9f..13847e5bd 100644
--- a/cipher.c
+++ b/cipher.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cipher.c,v 1.100 2015/01/14 10:29:45 djm Exp $ */ 1/* $OpenBSD: cipher.c,v 1.101 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -353,8 +353,7 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher,
353 if (cipher->discard_len > 0) { 353 if (cipher->discard_len > 0) {
354 if ((junk = malloc(cipher->discard_len)) == NULL || 354 if ((junk = malloc(cipher->discard_len)) == NULL ||
355 (discard = malloc(cipher->discard_len)) == NULL) { 355 (discard = malloc(cipher->discard_len)) == NULL) {
356 if (junk != NULL) 356 free(junk);
357 free(junk);
358 ret = SSH_ERR_ALLOC_FAIL; 357 ret = SSH_ERR_ALLOC_FAIL;
359 goto bad; 358 goto bad;
360 } 359 }
diff --git a/kex.c b/kex.c
index c1371c432..8243164f4 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.c,v 1.113 2015/12/04 16:41:28 markus Exp $ */ 1/* $OpenBSD: kex.c,v 1.114 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -906,8 +906,7 @@ derive_key(struct ssh *ssh, int id, u_int need, u_char *hash, u_int hashlen,
906 digest = NULL; 906 digest = NULL;
907 r = 0; 907 r = 0;
908 out: 908 out:
909 if (digest) 909 free(digest);
910 free(digest);
911 ssh_digest_free(hashctx); 910 ssh_digest_free(hashctx);
912 return r; 911 return r;
913} 912}
diff --git a/packet.c b/packet.c
index 378906956..06e16536c 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.218 2015/12/04 16:41:28 markus Exp $ */ 1/* $OpenBSD: packet.c,v 1.219 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -519,10 +519,8 @@ ssh_packet_close(struct ssh *ssh)
519 error("%s: cipher_cleanup failed: %s", __func__, ssh_err(r)); 519 error("%s: cipher_cleanup failed: %s", __func__, ssh_err(r));
520 if ((r = cipher_cleanup(&state->receive_context)) != 0) 520 if ((r = cipher_cleanup(&state->receive_context)) != 0)
521 error("%s: cipher_cleanup failed: %s", __func__, ssh_err(r)); 521 error("%s: cipher_cleanup failed: %s", __func__, ssh_err(r));
522 if (ssh->remote_ipaddr) { 522 free(ssh->remote_ipaddr);
523 free(ssh->remote_ipaddr); 523 ssh->remote_ipaddr = NULL;
524 ssh->remote_ipaddr = NULL;
525 }
526 free(ssh->state); 524 free(ssh->state);
527 ssh->state = NULL; 525 ssh->state = NULL;
528} 526}
@@ -1784,8 +1782,7 @@ ssh_packet_read_poll_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
1784 if ((r = sshpkt_get_u8(ssh, NULL)) != 0 || 1782 if ((r = sshpkt_get_u8(ssh, NULL)) != 0 ||
1785 (r = sshpkt_get_string(ssh, &msg, NULL)) != 0 || 1783 (r = sshpkt_get_string(ssh, &msg, NULL)) != 0 ||
1786 (r = sshpkt_get_string(ssh, NULL, NULL)) != 0) { 1784 (r = sshpkt_get_string(ssh, NULL, NULL)) != 0) {
1787 if (msg) 1785 free(msg);
1788 free(msg);
1789 return r; 1786 return r;
1790 } 1787 }
1791 debug("Remote: %.900s", msg); 1788 debug("Remote: %.900s", msg);
@@ -2570,8 +2567,7 @@ newkeys_from_blob(struct sshbuf *m, struct ssh *ssh, int mode)
2570 newkey = NULL; 2567 newkey = NULL;
2571 r = 0; 2568 r = 0;
2572 out: 2569 out:
2573 if (newkey != NULL) 2570 free(newkey);
2574 free(newkey);
2575 if (b != NULL) 2571 if (b != NULL)
2576 sshbuf_free(b); 2572 sshbuf_free(b);
2577 return r; 2573 return r;
diff --git a/ssh-dss.c b/ssh-dss.c
index 8ed19d849..254f2a39b 100644
--- a/ssh-dss.c
+++ b/ssh-dss.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-dss.c,v 1.32 2014/06/24 01:13:21 djm Exp $ */ 1/* $OpenBSD: ssh-dss.c,v 1.33 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * 4 *
@@ -211,8 +211,7 @@ ssh_dss_verify(const struct sshkey *key,
211 DSA_SIG_free(sig); 211 DSA_SIG_free(sig);
212 if (b != NULL) 212 if (b != NULL)
213 sshbuf_free(b); 213 sshbuf_free(b);
214 if (ktype != NULL) 214 free(ktype);
215 free(ktype);
216 if (sigblob != NULL) { 215 if (sigblob != NULL) {
217 explicit_bzero(sigblob, len); 216 explicit_bzero(sigblob, len);
218 free(sigblob); 217 free(sigblob);
diff --git a/ssh-rsa.c b/ssh-rsa.c
index 6b8589522..4eb00c87c 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-rsa.c,v 1.56 2015/12/07 20:04:09 markus Exp $ */ 1/* $OpenBSD: ssh-rsa.c,v 1.57 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> 3 * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org>
4 * 4 *
@@ -226,8 +226,7 @@ ssh_rsa_verify(const struct sshkey *key,
226 explicit_bzero(sigblob, len); 226 explicit_bzero(sigblob, len);
227 free(sigblob); 227 free(sigblob);
228 } 228 }
229 if (ktype != NULL) 229 free(ktype);
230 free(ktype);
231 if (b != NULL) 230 if (b != NULL)
232 sshbuf_free(b); 231 sshbuf_free(b);
233 explicit_bzero(digest, sizeof(digest)); 232 explicit_bzero(digest, sizeof(digest));
diff --git a/ssh.c b/ssh.c
index 38e2b6674..37dcdc705 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.430 2015/11/19 08:23:27 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.431 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -911,8 +911,7 @@ main(int ac, char **av)
911 subsystem_flag = 1; 911 subsystem_flag = 1;
912 break; 912 break;
913 case 'S': 913 case 'S':
914 if (options.control_path != NULL) 914 free(options.control_path);
915 free(options.control_path);
916 options.control_path = xstrdup(optarg); 915 options.control_path = xstrdup(optarg);
917 break; 916 break;
918 case 'b': 917 case 'b':
diff --git a/sshconnect2.c b/sshconnect2.c
index da1bd3847..3c5afe507 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect2.c,v 1.231 2015/12/04 16:41:28 markus Exp $ */ 1/* $OpenBSD: sshconnect2.c,v 1.232 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Damien Miller. All rights reserved. 4 * Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -1257,8 +1257,7 @@ load_identity_file(Identity *id)
1257 explicit_bzero(passphrase, strlen(passphrase)); 1257 explicit_bzero(passphrase, strlen(passphrase));
1258 free(passphrase); 1258 free(passphrase);
1259 } 1259 }
1260 if (comment) 1260 free(comment);
1261 free(comment);
1262 if (private != NULL || quit) 1261 if (private != NULL || quit)
1263 break; 1262 break;
1264 } 1263 }
diff --git a/sshd.c b/sshd.c
index 2f3f5b551..5d2e0a03c 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.461 2015/12/04 16:41:28 markus Exp $ */ 1/* $OpenBSD: sshd.c,v 1.462 2015/12/10 17:08:40 mmcc Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1257,8 +1257,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1257 for (;;) { 1257 for (;;) {
1258 if (received_sighup) 1258 if (received_sighup)
1259 sighup_restart(); 1259 sighup_restart();
1260 if (fdset != NULL) 1260 free(fdset);
1261 free(fdset);
1262 fdset = xcalloc(howmany(maxfd + 1, NFDBITS), 1261 fdset = xcalloc(howmany(maxfd + 1, NFDBITS),
1263 sizeof(fd_mask)); 1262 sizeof(fd_mask));
1264 1263
diff --git a/sshkey.c b/sshkey.c
index 587bf5b84..87abea1e0 100644
--- a/sshkey.c
+++ b/sshkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshkey.c,v 1.28 2015/12/04 16:41:28 markus Exp $ */ 1/* $OpenBSD: sshkey.c,v 1.29 2015/12/10 17:08:40 mmcc 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.
@@ -426,12 +426,10 @@ cert_free(struct sshkey_cert *cert)
426 sshbuf_free(cert->critical); 426 sshbuf_free(cert->critical);
427 if (cert->extensions != NULL) 427 if (cert->extensions != NULL)
428 sshbuf_free(cert->extensions); 428 sshbuf_free(cert->extensions);
429 if (cert->key_id != NULL) 429 free(cert->key_id);
430 free(cert->key_id);
431 for (i = 0; i < cert->nprincipals; i++) 430 for (i = 0; i < cert->nprincipals; i++)
432 free(cert->principals[i]); 431 free(cert->principals[i]);
433 if (cert->principals != NULL) 432 free(cert->principals);
434 free(cert->principals);
435 if (cert->signature_key != NULL) 433 if (cert->signature_key != NULL)
436 sshkey_free(cert->signature_key); 434 sshkey_free(cert->signature_key);
437 explicit_bzero(cert, sizeof(*cert)); 435 explicit_bzero(cert, sizeof(*cert));
@@ -2473,10 +2471,8 @@ sshkey_certify(struct sshkey *k, struct sshkey *ca)
2473 out: 2471 out:
2474 if (ret != 0) 2472 if (ret != 0)
2475 sshbuf_reset(cert); 2473 sshbuf_reset(cert);
2476 if (sig_blob != NULL) 2474 free(sig_blob);
2477 free(sig_blob); 2475 free(ca_blob);
2478 if (ca_blob != NULL)
2479 free(ca_blob);
2480 if (principals != NULL) 2476 if (principals != NULL)
2481 sshbuf_free(principals); 2477 sshbuf_free(principals);
2482 return ret; 2478 return ret;
@@ -3764,8 +3760,7 @@ sshkey_parse_private_rsa1(struct sshbuf *blob, const char *passphrase,
3764 } 3760 }
3765 out: 3761 out:
3766 explicit_bzero(&ciphercontext, sizeof(ciphercontext)); 3762 explicit_bzero(&ciphercontext, sizeof(ciphercontext));
3767 if (comment != NULL) 3763 free(comment);
3768 free(comment);
3769 if (prv != NULL) 3764 if (prv != NULL)
3770 sshkey_free(prv); 3765 sshkey_free(prv);
3771 if (copy != NULL) 3766 if (copy != NULL)