X-Git-Url: http://andersk.mit.edu/gitweb/gssapi-openssh.git/blobdiff_plain/39e70dec76acc4f638f7a209dcd8b4d40feba8f0..b5afdff53b51d529e596da3b4c2aa5ee14cc8b08:/openssh/ssh.c diff --git a/openssh/ssh.c b/openssh/ssh.c index f112134..21f4c84 100644 --- a/openssh/ssh.c +++ b/openssh/ssh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.324 2009/02/12 03:00:56 djm Exp $ */ +/* $OpenBSD: ssh.c,v 1.326 2009/07/02 02:11:47 dtucker Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -48,6 +48,7 @@ #endif #include #include +#include #include #include @@ -203,8 +204,8 @@ void muxserver_listen(void); int main(int ac, char **av) { - int i, opt, exit_status, use_syslog; - char *p, *cp, *line, buf[256]; + int i, r, opt, exit_status, use_syslog; + char *p, *cp, *line, *argv0, buf[MAXPATHLEN]; struct stat st; struct passwd *pw; int dummy, timeout_ms; @@ -270,6 +271,7 @@ main(int ac, char **av) /* Parse command-line arguments. */ host = NULL; use_syslog = 0; + argv0 = av[0]; again: while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx" @@ -604,7 +606,7 @@ main(int ac, char **av) * Initialize "log" output. Since we are the client all output * actually goes to stderr. */ - log_init(av[0], + log_init(argv0, options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level, SYSLOG_FACILITY_USER, !use_syslog); @@ -626,23 +628,27 @@ main(int ac, char **av) * options. */ #ifdef GSSAPI - snprintf(buf, sizeof buf, "%.100s/%.100s.gssapi", pw->pw_dir, + r = snprintf(buf, sizeof buf, "%s/%s.gssapi", pw->pw_dir, _PATH_SSH_USER_CONFFILE); - (void)read_config_file(buf, host, &options, 1); + if (r > 0 && (size_t)r < sizeof(buf)) + (void)read_config_file(buf, host, &options, 1); #ifdef GSI - snprintf(buf, sizeof buf, "%.100s/%.100s.gsi", pw->pw_dir, + r = snprintf(buf, sizeof buf, "%s/%s.gsi", pw->pw_dir, _PATH_SSH_USER_CONFFILE); - (void)read_config_file(buf, host, &options, 1); + if (r > 0 && (size_t)r < sizeof(buf)) + (void)read_config_file(buf, host, &options, 1); #endif #if defined(KRB5) - snprintf(buf, sizeof buf, "%.100s/%.100s.krb", pw->pw_dir, + r = snprintf(buf, sizeof buf, "%s/%s.krb", pw->pw_dir, _PATH_SSH_USER_CONFFILE); - (void)read_config_file(buf, host, &options, 1); + if (r > 0 && (size_t)r < sizeof(buf)) + (void)read_config_file(buf, host, &options, 1); #endif #endif - snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, + r = snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, _PATH_SSH_USER_CONFFILE); - (void)read_config_file(buf, host, &options, 1); + if (r > 0 && (size_t)r < sizeof(buf)) + (void)read_config_file(buf, host, &options, 1); /* Read systemwide configuration file after use config. */ (void)read_config_file(_PATH_HOST_CONFIG_FILE, host, @@ -655,7 +661,7 @@ main(int ac, char **av) channel_set_af(options.address_family); /* reinit */ - log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, !use_syslog); + log_init(argv0, options.log_level, SYSLOG_FACILITY_USER, !use_syslog); seed_rng(); @@ -796,9 +802,9 @@ main(int ac, char **av) * Now that we are back to our own permissions, create ~/.ssh * directory if it doesn't already exist. */ - snprintf(buf, sizeof buf, "%.100s%s%.100s", pw->pw_dir, + r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir, strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR); - if (stat(buf, &st) < 0) + if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) < 0) if (mkdir(buf, 0700) < 0) error("Could not create directory '%.200s'.", buf);