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 9d43bb74f..adfe60e4b 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"
@@ -600,7 +602,7 @@ main(int ac, char **av)
600 * Initialize "log" output. Since we are the client all output 602 * Initialize "log" output. Since we are the client all output
601 * actually goes to stderr. 603 * actually goes to stderr.
602 */ 604 */
603 log_init(av[0], 605 log_init(argv0,
604 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level, 606 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
605 SYSLOG_FACILITY_USER, !use_syslog); 607 SYSLOG_FACILITY_USER, !use_syslog);
606 608
@@ -613,9 +615,10 @@ main(int ac, char **av)
613 fatal("Can't open user config file %.100s: " 615 fatal("Can't open user config file %.100s: "
614 "%.100s", config, strerror(errno)); 616 "%.100s", config, strerror(errno));
615 } else { 617 } else {
616 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, 618 r = snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir,
617 _PATH_SSH_USER_CONFFILE); 619 _PATH_SSH_USER_CONFFILE);
618 (void)read_config_file(buf, host, &options, 1); 620 if (r > 0 && (size_t)r < sizeof(buf))
621 (void)read_config_file(buf, host, &options, 1);
619 622
620 /* Read systemwide configuration file after use config. */ 623 /* Read systemwide configuration file after use config. */
621 (void)read_config_file(_PATH_HOST_CONFIG_FILE, host, 624 (void)read_config_file(_PATH_HOST_CONFIG_FILE, host,
@@ -628,7 +631,7 @@ main(int ac, char **av)
628 channel_set_af(options.address_family); 631 channel_set_af(options.address_family);
629 632
630 /* reinit */ 633 /* reinit */
631 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, !use_syslog); 634 log_init(argv0, options.log_level, SYSLOG_FACILITY_USER, !use_syslog);
632 635
633 seed_rng(); 636 seed_rng();
634 637
@@ -766,9 +769,9 @@ main(int ac, char **av)
766 * Now that we are back to our own permissions, create ~/.ssh 769 * Now that we are back to our own permissions, create ~/.ssh
767 * directory if it doesn't already exist. 770 * directory if it doesn't already exist.
768 */ 771 */
769 snprintf(buf, sizeof buf, "%.100s%s%.100s", pw->pw_dir, 772 r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir,
770 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR); 773 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
771 if (stat(buf, &st) < 0) 774 if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) < 0)
772 if (mkdir(buf, 0700) < 0) 775 if (mkdir(buf, 0700) < 0)
773 error("Could not create directory '%.200s'.", buf); 776 error("Could not create directory '%.200s'.", buf);
774 777