summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/ssh.c b/ssh.c
index 9e1a4b797..a72f16c63 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.324 2009/02/12 03:00:56 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.326 2009/07/02 02:11: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
@@ -48,6 +48,7 @@
48#endif 48#endif
49#include <sys/resource.h> 49#include <sys/resource.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/param.h>
51#include <sys/socket.h> 52#include <sys/socket.h>
52 53
53#include <ctype.h> 54#include <ctype.h>
@@ -203,8 +204,8 @@ void muxserver_listen(void);
203int 204int
204main(int ac, char **av) 205main(int ac, char **av)
205{ 206{
206 int i, opt, exit_status, use_syslog; 207 int i, r, opt, exit_status, use_syslog;
207 char *p, *cp, *line, buf[256]; 208 char *p, *cp, *line, *argv0, buf[MAXPATHLEN];
208 struct stat st; 209 struct stat st;
209 struct passwd *pw; 210 struct passwd *pw;
210 int dummy, timeout_ms; 211 int dummy, timeout_ms;
@@ -270,6 +271,7 @@ main(int ac, char **av)
270 /* Parse command-line arguments. */ 271 /* Parse command-line arguments. */
271 host = NULL; 272 host = NULL;
272 use_syslog = 0; 273 use_syslog = 0;
274 argv0 = av[0];
273 275
274 again: 276 again:
275 while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx" 277 while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx"
@@ -605,7 +607,7 @@ main(int ac, char **av)
605 * Initialize "log" output. Since we are the client all output 607 * Initialize "log" output. Since we are the client all output
606 * actually goes to stderr. 608 * actually goes to stderr.
607 */ 609 */
608 log_init(av[0], 610 log_init(argv0,
609 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level, 611 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
610 SYSLOG_FACILITY_USER, !use_syslog); 612 SYSLOG_FACILITY_USER, !use_syslog);
611 613
@@ -618,9 +620,10 @@ main(int ac, char **av)
618 fatal("Can't open user config file %.100s: " 620 fatal("Can't open user config file %.100s: "
619 "%.100s", config, strerror(errno)); 621 "%.100s", config, strerror(errno));
620 } else { 622 } else {
621 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, 623 r = snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir,
622 _PATH_SSH_USER_CONFFILE); 624 _PATH_SSH_USER_CONFFILE);
623 (void)read_config_file(buf, host, &options, 1); 625 if (r > 0 && (size_t)r < sizeof(buf))
626 (void)read_config_file(buf, host, &options, 1);
624 627
625 /* Read systemwide configuration file after use config. */ 628 /* Read systemwide configuration file after use config. */
626 (void)read_config_file(_PATH_HOST_CONFIG_FILE, host, 629 (void)read_config_file(_PATH_HOST_CONFIG_FILE, host,
@@ -633,7 +636,7 @@ main(int ac, char **av)
633 channel_set_af(options.address_family); 636 channel_set_af(options.address_family);
634 637
635 /* reinit */ 638 /* reinit */
636 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, !use_syslog); 639 log_init(argv0, options.log_level, SYSLOG_FACILITY_USER, !use_syslog);
637 640
638 seed_rng(); 641 seed_rng();
639 642
@@ -771,9 +774,9 @@ main(int ac, char **av)
771 * Now that we are back to our own permissions, create ~/.ssh 774 * Now that we are back to our own permissions, create ~/.ssh
772 * directory if it doesn't already exist. 775 * directory if it doesn't already exist.
773 */ 776 */
774 snprintf(buf, sizeof buf, "%.100s%s%.100s", pw->pw_dir, 777 r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir,
775 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR); 778 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
776 if (stat(buf, &st) < 0) 779 if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) < 0)
777 if (mkdir(buf, 0700) < 0) 780 if (mkdir(buf, 0700) < 0)
778 error("Could not create directory '%.200s'.", buf); 781 error("Could not create directory '%.200s'.", buf);
779 782