summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authorderaadt@openbsd.org <deraadt@openbsd.org>2019-06-28 13:35:04 +0000
committerDamien Miller <djm@mindrot.org>2019-07-05 11:10:39 +1000
commit4d28fa78abce2890e136281950633fae2066cc29 (patch)
tree33226ec64ced661bb7e40005e30744b68fa59a80 /ssh.c
parente8c974043c1648eab0ad67a7ba6a3e444fe79d2d (diff)
upstream: When system calls indicate an error they return -1, not
some arbitrary value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future. OpenBSD-Commit-ID: 48081f00db7518e3b712a49dca06efc2a5428075
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/ssh.c b/ssh.c
index d9a9d1136..654376981 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.504 2019/06/14 04:13:58 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.505 2019/06/28 13:35:04 deraadt 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
@@ -773,7 +773,7 @@ main(int ac, char **av)
773 break; 773 break;
774 case 'i': 774 case 'i':
775 p = tilde_expand_filename(optarg, getuid()); 775 p = tilde_expand_filename(optarg, getuid());
776 if (stat(p, &st) < 0) 776 if (stat(p, &st) == -1)
777 fprintf(stderr, "Warning: Identity file %s " 777 fprintf(stderr, "Warning: Identity file %s "
778 "not accessible: %s.\n", p, 778 "not accessible: %s.\n", p,
779 strerror(errno)); 779 strerror(errno));
@@ -1426,7 +1426,7 @@ main(int ac, char **av)
1426 if (config == NULL) { 1426 if (config == NULL) {
1427 r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir, 1427 r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir,
1428 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR); 1428 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
1429 if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) < 0) { 1429 if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) == -1) {
1430#ifdef WITH_SELINUX 1430#ifdef WITH_SELINUX
1431 ssh_selinux_setfscreatecon(buf); 1431 ssh_selinux_setfscreatecon(buf);
1432#endif 1432#endif
@@ -1593,7 +1593,7 @@ fork_postauth(void)
1593 control_persist_detach(); 1593 control_persist_detach();
1594 debug("forking to background"); 1594 debug("forking to background");
1595 fork_after_authentication_flag = 0; 1595 fork_after_authentication_flag = 0;
1596 if (daemon(1, 1) < 0) 1596 if (daemon(1, 1) == -1)
1597 fatal("daemon() failed: %.200s", strerror(errno)); 1597 fatal("daemon() failed: %.200s", strerror(errno));
1598} 1598}
1599 1599
@@ -1689,8 +1689,8 @@ ssh_init_stdio_forwarding(struct ssh *ssh)
1689 debug3("%s: %s:%d", __func__, options.stdio_forward_host, 1689 debug3("%s: %s:%d", __func__, options.stdio_forward_host,
1690 options.stdio_forward_port); 1690 options.stdio_forward_port);
1691 1691
1692 if ((in = dup(STDIN_FILENO)) < 0 || 1692 if ((in = dup(STDIN_FILENO)) == -1 ||
1693 (out = dup(STDOUT_FILENO)) < 0) 1693 (out = dup(STDOUT_FILENO)) == -1)
1694 fatal("channel_connect_stdio_fwd: dup() in/out failed"); 1694 fatal("channel_connect_stdio_fwd: dup() in/out failed");
1695 if ((c = channel_connect_stdio_fwd(ssh, options.stdio_forward_host, 1695 if ((c = channel_connect_stdio_fwd(ssh, options.stdio_forward_host,
1696 options.stdio_forward_port, in, out)) == NULL) 1696 options.stdio_forward_port, in, out)) == NULL)
@@ -1843,7 +1843,7 @@ ssh_session2_open(struct ssh *ssh)
1843 out = dup(STDOUT_FILENO); 1843 out = dup(STDOUT_FILENO);
1844 err = dup(STDERR_FILENO); 1844 err = dup(STDERR_FILENO);
1845 1845
1846 if (in < 0 || out < 0 || err < 0) 1846 if (in == -1 || out == -1 || err == -1)
1847 fatal("dup() in/out/err failed"); 1847 fatal("dup() in/out/err failed");
1848 1848
1849 /* enable nonblocking unless tty */ 1849 /* enable nonblocking unless tty */
@@ -1974,7 +1974,7 @@ ssh_session2(struct ssh *ssh, struct passwd *pw)
1974 if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1) 1974 if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1)
1975 error("%s: open %s: %s", __func__, 1975 error("%s: open %s: %s", __func__,
1976 _PATH_DEVNULL, strerror(errno)); 1976 _PATH_DEVNULL, strerror(errno));
1977 if (dup2(devnull, STDOUT_FILENO) < 0) 1977 if (dup2(devnull, STDOUT_FILENO) == -1)
1978 fatal("%s: dup2() stdout failed", __func__); 1978 fatal("%s: dup2() stdout failed", __func__);
1979 if (devnull > STDERR_FILENO) 1979 if (devnull > STDERR_FILENO)
1980 close(devnull); 1980 close(devnull);
@@ -2161,7 +2161,7 @@ main_sigchld_handler(int sig)
2161 int status; 2161 int status;
2162 2162
2163 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || 2163 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
2164 (pid < 0 && errno == EINTR)) 2164 (pid == -1 && errno == EINTR))
2165 ; 2165 ;
2166 errno = save_errno; 2166 errno = save_errno;
2167} 2167}