summaryrefslogtreecommitdiff
path: root/sshd.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 /sshd.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 'sshd.c')
-rw-r--r--sshd.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/sshd.c b/sshd.c
index 735a11060..11571c010 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.536 2019/06/21 04:21:05 djm Exp $ */ 1/* $OpenBSD: sshd.c,v 1.537 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
@@ -345,7 +345,7 @@ main_sigchld_handler(int sig)
345 int status; 345 int status;
346 346
347 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || 347 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
348 (pid < 0 && errno == EINTR)) 348 (pid == -1 && errno == EINTR))
349 ; 349 ;
350 errno = save_errno; 350 errno = save_errno;
351} 351}
@@ -468,7 +468,7 @@ privsep_preauth_child(void)
468 debug3("privsep user:group %u:%u", (u_int)privsep_pw->pw_uid, 468 debug3("privsep user:group %u:%u", (u_int)privsep_pw->pw_uid,
469 (u_int)privsep_pw->pw_gid); 469 (u_int)privsep_pw->pw_gid);
470 gidset[0] = privsep_pw->pw_gid; 470 gidset[0] = privsep_pw->pw_gid;
471 if (setgroups(1, gidset) < 0) 471 if (setgroups(1, gidset) == -1)
472 fatal("setgroups: %.100s", strerror(errno)); 472 fatal("setgroups: %.100s", strerror(errno));
473 permanently_set_uid(privsep_pw); 473 permanently_set_uid(privsep_pw);
474 } 474 }
@@ -508,7 +508,7 @@ privsep_preauth(struct ssh *ssh)
508 monitor_child_preauth(ssh, pmonitor); 508 monitor_child_preauth(ssh, pmonitor);
509 509
510 /* Wait for the child's exit status */ 510 /* Wait for the child's exit status */
511 while (waitpid(pid, &status, 0) < 0) { 511 while (waitpid(pid, &status, 0) == -1) {
512 if (errno == EINTR) 512 if (errno == EINTR)
513 continue; 513 continue;
514 pmonitor->m_pid = -1; 514 pmonitor->m_pid = -1;
@@ -967,7 +967,7 @@ listen_on_addrs(struct listenaddr *la)
967 /* Create socket for listening. */ 967 /* Create socket for listening. */
968 listen_sock = socket(ai->ai_family, ai->ai_socktype, 968 listen_sock = socket(ai->ai_family, ai->ai_socktype,
969 ai->ai_protocol); 969 ai->ai_protocol);
970 if (listen_sock < 0) { 970 if (listen_sock == -1) {
971 /* kernel may not support ipv6 */ 971 /* kernel may not support ipv6 */
972 verbose("socket: %.100s", strerror(errno)); 972 verbose("socket: %.100s", strerror(errno));
973 continue; 973 continue;
@@ -996,7 +996,7 @@ listen_on_addrs(struct listenaddr *la)
996 debug("Bind to port %s on %s.", strport, ntop); 996 debug("Bind to port %s on %s.", strport, ntop);
997 997
998 /* Bind the socket to the desired port. */ 998 /* Bind the socket to the desired port. */
999 if (bind(listen_sock, ai->ai_addr, ai->ai_addrlen) < 0) { 999 if (bind(listen_sock, ai->ai_addr, ai->ai_addrlen) == -1) {
1000 error("Bind to port %s on %s failed: %.200s.", 1000 error("Bind to port %s on %s failed: %.200s.",
1001 strport, ntop, strerror(errno)); 1001 strport, ntop, strerror(errno));
1002 close(listen_sock); 1002 close(listen_sock);
@@ -1006,7 +1006,7 @@ listen_on_addrs(struct listenaddr *la)
1006 num_listen_socks++; 1006 num_listen_socks++;
1007 1007
1008 /* Start listening on the port. */ 1008 /* Start listening on the port. */
1009 if (listen(listen_sock, SSH_LISTEN_BACKLOG) < 0) 1009 if (listen(listen_sock, SSH_LISTEN_BACKLOG) == -1)
1010 fatal("listen on [%s]:%s: %.100s", 1010 fatal("listen on [%s]:%s: %.100s",
1011 ntop, strport, strerror(errno)); 1011 ntop, strport, strerror(errno));
1012 logit("Server listening on %s port %s%s%s.", 1012 logit("Server listening on %s port %s%s%s.",
@@ -1091,7 +1091,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1091 1091
1092 /* Wait in select until there is a connection. */ 1092 /* Wait in select until there is a connection. */
1093 ret = select(maxfd+1, fdset, NULL, NULL, NULL); 1093 ret = select(maxfd+1, fdset, NULL, NULL, NULL);
1094 if (ret < 0 && errno != EINTR) 1094 if (ret == -1 && errno != EINTR)
1095 error("select: %.100s", strerror(errno)); 1095 error("select: %.100s", strerror(errno));
1096 if (received_sigterm) { 1096 if (received_sigterm) {
1097 logit("Received signal %d; terminating.", 1097 logit("Received signal %d; terminating.",
@@ -1101,7 +1101,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1101 unlink(options.pid_file); 1101 unlink(options.pid_file);
1102 exit(received_sigterm == SIGTERM ? 0 : 255); 1102 exit(received_sigterm == SIGTERM ? 0 : 255);
1103 } 1103 }
1104 if (ret < 0) 1104 if (ret == -1)
1105 continue; 1105 continue;
1106 1106
1107 for (i = 0; i < options.max_startups; i++) { 1107 for (i = 0; i < options.max_startups; i++) {
@@ -1141,7 +1141,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1141 fromlen = sizeof(from); 1141 fromlen = sizeof(from);
1142 *newsock = accept(listen_socks[i], 1142 *newsock = accept(listen_socks[i],
1143 (struct sockaddr *)&from, &fromlen); 1143 (struct sockaddr *)&from, &fromlen);
1144 if (*newsock < 0) { 1144 if (*newsock == -1) {
1145 if (errno != EINTR && errno != EWOULDBLOCK && 1145 if (errno != EINTR && errno != EWOULDBLOCK &&
1146 errno != ECONNABORTED && errno != EAGAIN) 1146 errno != ECONNABORTED && errno != EAGAIN)
1147 error("accept: %.100s", 1147 error("accept: %.100s",
@@ -1261,7 +1261,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1261 1261
1262 /* Parent. Stay in the loop. */ 1262 /* Parent. Stay in the loop. */
1263 platform_post_fork_parent(pid); 1263 platform_post_fork_parent(pid);
1264 if (pid < 0) 1264 if (pid == -1)
1265 error("fork: %.100s", strerror(errno)); 1265 error("fork: %.100s", strerror(errno));
1266 else 1266 else
1267 debug("Forked child %ld.", (long)pid); 1267 debug("Forked child %ld.", (long)pid);
@@ -1314,7 +1314,7 @@ check_ip_options(struct ssh *ssh)
1314 1314
1315 memset(&from, 0, sizeof(from)); 1315 memset(&from, 0, sizeof(from));
1316 if (getpeername(sock_in, (struct sockaddr *)&from, 1316 if (getpeername(sock_in, (struct sockaddr *)&from,
1317 &fromlen) < 0) 1317 &fromlen) == -1)
1318 return; 1318 return;
1319 if (from.ss_family != AF_INET) 1319 if (from.ss_family != AF_INET)
1320 return; 1320 return;
@@ -1895,7 +1895,7 @@ main(int ac, char **av)
1895 already_daemon = daemonized(); 1895 already_daemon = daemonized();
1896 if (!(debug_flag || inetd_flag || no_daemon_flag || already_daemon)) { 1896 if (!(debug_flag || inetd_flag || no_daemon_flag || already_daemon)) {
1897 1897
1898 if (daemon(0, 0) < 0) 1898 if (daemon(0, 0) == -1)
1899 fatal("daemon() failed: %.200s", strerror(errno)); 1899 fatal("daemon() failed: %.200s", strerror(errno));
1900 1900
1901 disconnect_controlling_tty(); 1901 disconnect_controlling_tty();
@@ -1958,7 +1958,7 @@ main(int ac, char **av)
1958 * controlling terminal which will result in "could not set 1958 * controlling terminal which will result in "could not set
1959 * controlling tty" errors. 1959 * controlling tty" errors.
1960 */ 1960 */
1961 if (!debug_flag && !inetd_flag && setsid() < 0) 1961 if (!debug_flag && !inetd_flag && setsid() == -1)
1962 error("setsid: %.100s", strerror(errno)); 1962 error("setsid: %.100s", strerror(errno));
1963#endif 1963#endif
1964 1964
@@ -2036,7 +2036,7 @@ main(int ac, char **av)
2036 2036
2037 /* Set SO_KEEPALIVE if requested. */ 2037 /* Set SO_KEEPALIVE if requested. */
2038 if (options.tcp_keep_alive && ssh_packet_connection_is_on_socket(ssh) && 2038 if (options.tcp_keep_alive && ssh_packet_connection_is_on_socket(ssh) &&
2039 setsockopt(sock_in, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) < 0) 2039 setsockopt(sock_in, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) == -1)
2040 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); 2040 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
2041 2041
2042 if ((remote_port = ssh_remote_port(ssh)) < 0) { 2042 if ((remote_port = ssh_remote_port(ssh)) < 0) {