summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2015-09-04 08:21:47 +0000
committerDamien Miller <djm@mindrot.org>2015-09-11 13:28:00 +1000
commit4f7cc2f8cc861a21e6dbd7f6c25652afb38b9b96 (patch)
treeac729ec5e2b5f386d982ba870cb5c4589d127dd8
parent7ad8b287c8453a3e61dbc0d34d467632b8b06fc8 (diff)
upstream commit
Plug minor memory leaks when options are used more than once. bz#2182, patch from Tiago Cunha, ok deraadt djm Upstream-ID: 5b84d0401e27fe1614c10997010cc55933adb48e
-rw-r--r--ssh.c15
-rw-r--r--sshd.c8
2 files changed, 11 insertions, 12 deletions
diff --git a/ssh.c b/ssh.c
index 6053db219..bf8c9c646 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.421 2015/09/04 04:56:09 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.422 2015/09/04 08:21:47 dtucker 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
@@ -627,7 +627,7 @@ main(int ac, char **av)
627 use_syslog = 1; 627 use_syslog = 1;
628 break; 628 break;
629 case 'E': 629 case 'E':
630 logfile = xstrdup(optarg); 630 logfile = optarg;
631 break; 631 break;
632 case 'G': 632 case 'G':
633 config_test = 1; 633 config_test = 1;
@@ -714,6 +714,7 @@ main(int ac, char **av)
714 break; 714 break;
715 case 'I': 715 case 'I':
716#ifdef ENABLE_PKCS11 716#ifdef ENABLE_PKCS11
717 free(options.pkcs11_provider);
717 options.pkcs11_provider = xstrdup(optarg); 718 options.pkcs11_provider = xstrdup(optarg);
718#else 719#else
719 fprintf(stderr, "no support for PKCS#11.\n"); 720 fprintf(stderr, "no support for PKCS#11.\n");
@@ -798,6 +799,7 @@ main(int ac, char **av)
798 if (ciphers_valid(*optarg == '+' ? 799 if (ciphers_valid(*optarg == '+' ?
799 optarg + 1 : optarg)) { 800 optarg + 1 : optarg)) {
800 /* SSH2 only */ 801 /* SSH2 only */
802 free(options.ciphers);
801 options.ciphers = xstrdup(optarg); 803 options.ciphers = xstrdup(optarg);
802 options.cipher = SSH_CIPHER_INVALID; 804 options.cipher = SSH_CIPHER_INVALID;
803 break; 805 break;
@@ -817,9 +819,10 @@ main(int ac, char **av)
817 options.ciphers = xstrdup(KEX_CLIENT_ENCRYPT); 819 options.ciphers = xstrdup(KEX_CLIENT_ENCRYPT);
818 break; 820 break;
819 case 'm': 821 case 'm':
820 if (mac_valid(optarg)) 822 if (mac_valid(optarg)) {
823 free(options.macs);
821 options.macs = xstrdup(optarg); 824 options.macs = xstrdup(optarg);
822 else { 825 } else {
823 fprintf(stderr, "Unknown mac type '%s'\n", 826 fprintf(stderr, "Unknown mac type '%s'\n",
824 optarg); 827 optarg);
825 exit(255); 828 exit(255);
@@ -980,10 +983,8 @@ main(int ac, char **av)
980 */ 983 */
981 if (use_syslog && logfile != NULL) 984 if (use_syslog && logfile != NULL)
982 fatal("Can't specify both -y and -E"); 985 fatal("Can't specify both -y and -E");
983 if (logfile != NULL) { 986 if (logfile != NULL)
984 log_redirect_stderr_to(logfile); 987 log_redirect_stderr_to(logfile);
985 free(logfile);
986 }
987 log_init(argv0, 988 log_init(argv0,
988 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level, 989 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
989 SYSLOG_FACILITY_USER, !use_syslog); 990 SYSLOG_FACILITY_USER, !use_syslog);
diff --git a/sshd.c b/sshd.c
index 65ef7e850..d86808912 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.458 2015/08/20 22:32:42 deraadt Exp $ */ 1/* $OpenBSD: sshd.c,v 1.459 2015/09/04 08:21:47 dtucker 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
@@ -1530,7 +1530,7 @@ main(int ac, char **av)
1530 no_daemon_flag = 1; 1530 no_daemon_flag = 1;
1531 break; 1531 break;
1532 case 'E': 1532 case 'E':
1533 logfile = xstrdup(optarg); 1533 logfile = optarg;
1534 /* FALLTHROUGH */ 1534 /* FALLTHROUGH */
1535 case 'e': 1535 case 'e':
1536 log_stderr = 1; 1536 log_stderr = 1;
@@ -1632,10 +1632,8 @@ main(int ac, char **av)
1632#endif 1632#endif
1633 1633
1634 /* If requested, redirect the logs to the specified logfile. */ 1634 /* If requested, redirect the logs to the specified logfile. */
1635 if (logfile != NULL) { 1635 if (logfile != NULL)
1636 log_redirect_stderr_to(logfile); 1636 log_redirect_stderr_to(logfile);
1637 free(logfile);
1638 }
1639 /* 1637 /*
1640 * Force logging to stderr until we have loaded the private host 1638 * Force logging to stderr until we have loaded the private host
1641 * key (unless started from inetd) 1639 * key (unless started from inetd)