X-Git-Url: http://andersk.mit.edu/gitweb/openssh.git/blobdiff_plain/bd7c69eaa251af6b0a2c8218fa5b690c7c4e897d..52e3daedec4da996f923934417982ace52d0b981:/ssh.c diff --git a/ssh.c b/ssh.c index 5331402e..f34be679 100644 --- a/ssh.c +++ b/ssh.c @@ -40,12 +40,20 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh.c,v 1.260 2006/02/10 00:27:13 stevesk Exp $"); +#include +#ifdef HAVE_SYS_STAT_H +# include +#endif #include #include +#include +#include +#ifdef HAVE_PATHS_H #include +#endif +#include #include #include @@ -247,7 +255,7 @@ main(int ac, char **av) /* Parse command-line arguments. */ host = NULL; -again: + again: while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvxACD:F:I:L:MNO:PR:S:TVw:XY")) != -1) { switch (opt) { @@ -621,7 +629,7 @@ again: if (options.host_key_alias != NULL) { for (p = options.host_key_alias; *p; p++) if (isupper(*p)) - *p = tolower(*p); + *p = (char)tolower(*p); } /* Get default port if port has not been set. */ @@ -638,11 +646,15 @@ again: options.control_path = NULL; if (options.control_path != NULL) { + char me[NI_MAXHOST]; + + if (gethostname(me, sizeof(me)) == -1) + fatal("gethostname: %s", strerror(errno)); snprintf(buf, sizeof(buf), "%d", options.port); cp = tilde_expand_filename(options.control_path, original_real_uid); options.control_path = percent_expand(cp, "p", buf, "h", host, - "r", options.user, (char *)NULL); + "r", options.user, "l", me, (char *)NULL); xfree(cp); } if (mux_command != 0 && options.control_path == NULL) @@ -675,7 +687,7 @@ again: if (options.rhosts_rsa_authentication || options.hostbased_authentication) { sensitive_data.nkeys = 3; - sensitive_data.keys = xmalloc(sensitive_data.nkeys * + sensitive_data.keys = xcalloc(sensitive_data.nkeys, sizeof(Key)); PRIV_START; @@ -877,10 +889,10 @@ ssh_session(void) /* Store window size in the packet. */ if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0) memset(&ws, 0, sizeof(ws)); - packet_put_int(ws.ws_row); - packet_put_int(ws.ws_col); - packet_put_int(ws.ws_xpixel); - packet_put_int(ws.ws_ypixel); + packet_put_int((u_int)ws.ws_row); + packet_put_int((u_int)ws.ws_col); + packet_put_int((u_int)ws.ws_xpixel); + packet_put_int((u_int)ws.ws_ypixel); /* Store tty modes in the packet. */ tty_make_modes(fileno(stdin), NULL); @@ -1029,7 +1041,7 @@ ssh_control_listener(void) fatal("%s socket(): %s", __func__, strerror(errno)); old_umask = umask(0177); - if (bind(control_fd, (struct sockaddr*)&addr, addr_len) == -1) { + if (bind(control_fd, (struct sockaddr *)&addr, addr_len) == -1) { control_fd = -1; if (errno == EINVAL || errno == EADDRINUSE) fatal("ControlSocket %s already exists", @@ -1238,7 +1250,8 @@ env_permitted(char *env) int i; char name[1024], *cp; - strlcpy(name, env, sizeof(name)); + if (strlcpy(name, env, sizeof(name)) >= sizeof(name)) + fatal("env_permitted: name too long"); if ((cp = strchr(name, '=')) == NULL) return (0); @@ -1287,29 +1300,29 @@ control_client(const char *path) if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) fatal("%s socket(): %s", __func__, strerror(errno)); - if (connect(sock, (struct sockaddr*)&addr, addr_len) == -1) { + if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) { if (mux_command != SSHMUX_COMMAND_OPEN) { fatal("Control socket connect(%.100s): %s", path, strerror(errno)); } if (errno == ENOENT) - debug("Control socket \"%.100s\" does not exist", path); + debug("Control socket \"%.100s\" does not exist", path); else { - error("Control socket connect(%.100s): %s", path, + error("Control socket connect(%.100s): %s", path, strerror(errno)); } - close(sock); - return; - } - - if (stdin_null_flag) { - if ((fd = open(_PATH_DEVNULL, O_RDONLY)) == -1) - fatal("open(/dev/null): %s", strerror(errno)); - if (dup2(fd, STDIN_FILENO) == -1) - fatal("dup2: %s", strerror(errno)); - if (fd > STDERR_FILENO) - close(fd); - } + close(sock); + return; + } + + if (stdin_null_flag) { + if ((fd = open(_PATH_DEVNULL, O_RDONLY)) == -1) + fatal("open(/dev/null): %s", strerror(errno)); + if (dup2(fd, STDIN_FILENO) == -1) + fatal("dup2: %s", strerror(errno)); + if (fd > STDERR_FILENO) + close(fd); + } term = getenv("TERM");