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
This commit is contained in:
dtucker@openbsd.org 2015-09-04 08:21:47 +00:00 committed by Damien Miller
parent 7ad8b287c8
commit 4f7cc2f8cc
2 changed files with 11 additions and 12 deletions

15
ssh.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssh.c,v 1.421 2015/09/04 04:56:09 djm Exp $ */
/* $OpenBSD: ssh.c,v 1.422 2015/09/04 08:21:47 dtucker Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -627,7 +627,7 @@ main(int ac, char **av)
use_syslog = 1;
break;
case 'E':
logfile = xstrdup(optarg);
logfile = optarg;
break;
case 'G':
config_test = 1;
@ -714,6 +714,7 @@ main(int ac, char **av)
break;
case 'I':
#ifdef ENABLE_PKCS11
free(options.pkcs11_provider);
options.pkcs11_provider = xstrdup(optarg);
#else
fprintf(stderr, "no support for PKCS#11.\n");
@ -798,6 +799,7 @@ main(int ac, char **av)
if (ciphers_valid(*optarg == '+' ?
optarg + 1 : optarg)) {
/* SSH2 only */
free(options.ciphers);
options.ciphers = xstrdup(optarg);
options.cipher = SSH_CIPHER_INVALID;
break;
@ -817,9 +819,10 @@ main(int ac, char **av)
options.ciphers = xstrdup(KEX_CLIENT_ENCRYPT);
break;
case 'm':
if (mac_valid(optarg))
if (mac_valid(optarg)) {
free(options.macs);
options.macs = xstrdup(optarg);
else {
} else {
fprintf(stderr, "Unknown mac type '%s'\n",
optarg);
exit(255);
@ -980,10 +983,8 @@ main(int ac, char **av)
*/
if (use_syslog && logfile != NULL)
fatal("Can't specify both -y and -E");
if (logfile != NULL) {
if (logfile != NULL)
log_redirect_stderr_to(logfile);
free(logfile);
}
log_init(argv0,
options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
SYSLOG_FACILITY_USER, !use_syslog);

8
sshd.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: sshd.c,v 1.458 2015/08/20 22:32:42 deraadt Exp $ */
/* $OpenBSD: sshd.c,v 1.459 2015/09/04 08:21:47 dtucker Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -1530,7 +1530,7 @@ main(int ac, char **av)
no_daemon_flag = 1;
break;
case 'E':
logfile = xstrdup(optarg);
logfile = optarg;
/* FALLTHROUGH */
case 'e':
log_stderr = 1;
@ -1632,10 +1632,8 @@ main(int ac, char **av)
#endif
/* If requested, redirect the logs to the specified logfile. */
if (logfile != NULL) {
if (logfile != NULL)
log_redirect_stderr_to(logfile);
free(logfile);
}
/*
* Force logging to stderr until we have loaded the private host
* key (unless started from inetd)