summaryrefslogtreecommitdiff
path: root/channels.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 /channels.c
parente8c974043c1648eab0ad67a7ba6a3e444fe79d2d (diff)
downloadopenssh-git-4d28fa78abce2890e136281950633fae2066cc29.tar.gz
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 'channels.c')
-rw-r--r--channels.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/channels.c b/channels.c
index 30691c82..e1c7be81 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.392 2019/06/07 14:18:48 dtucker Exp $ */
+/* $OpenBSD: channels.c,v 1.393 2019/06/28 13:35:04 deraadt Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1671,7 +1671,7 @@ channel_post_x11_listener(struct ssh *ssh, Channel *c,
chan_mark_dead(ssh, c);
errno = oerrno;
}
- if (newsock < 0) {
+ if (newsock == -1) {
if (errno != EINTR && errno != EWOULDBLOCK &&
errno != ECONNABORTED)
error("accept: %.100s", strerror(errno));
@@ -1814,7 +1814,7 @@ channel_post_port_listener(struct ssh *ssh, Channel *c,
addrlen = sizeof(addr);
newsock = accept(c->sock, (struct sockaddr *)&addr, &addrlen);
- if (newsock < 0) {
+ if (newsock == -1) {
if (errno != EINTR && errno != EWOULDBLOCK &&
errno != ECONNABORTED)
error("accept: %.100s", strerror(errno));
@@ -1853,7 +1853,7 @@ channel_post_auth_listener(struct ssh *ssh, Channel *c,
addrlen = sizeof(addr);
newsock = accept(c->sock, (struct sockaddr *)&addr, &addrlen);
- if (newsock < 0) {
+ if (newsock == -1) {
error("accept from auth socket: %.100s", strerror(errno));
if (errno == EMFILE || errno == ENFILE)
c->notbefore = monotime() + 1;
@@ -1881,7 +1881,7 @@ channel_post_connecting(struct ssh *ssh, Channel *c,
fatal(":%s: channel %d: no remote id", __func__, c->self);
/* for rdynamic the OPEN_CONFIRMATION has been sent already */
isopen = (c->type == SSH_CHANNEL_RDYNAMIC_FINISH);
- if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) {
+ if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &err, &sz) == -1) {
err = errno;
error("getsockopt SO_ERROR failed");
}
@@ -1956,7 +1956,7 @@ channel_handle_rfd(struct ssh *ssh, Channel *c,
errno = 0;
len = read(c->rfd, buf, sizeof(buf));
- if (len < 0 && (errno == EINTR ||
+ if (len == -1 && (errno == EINTR ||
((errno == EAGAIN || errno == EWOULDBLOCK) && !force)))
return 1;
#ifndef PTY_ZEROREAD
@@ -2030,7 +2030,7 @@ channel_handle_wfd(struct ssh *ssh, Channel *c,
/* ignore truncated writes, datagrams might get lost */
len = write(c->wfd, buf, dlen);
free(data);
- if (len < 0 && (errno == EINTR || errno == EAGAIN ||
+ if (len == -1 && (errno == EINTR || errno == EAGAIN ||
errno == EWOULDBLOCK))
return 1;
if (len <= 0)
@@ -2045,7 +2045,7 @@ channel_handle_wfd(struct ssh *ssh, Channel *c,
#endif
len = write(c->wfd, buf, dlen);
- if (len < 0 &&
+ if (len == -1 &&
(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
return 1;
if (len <= 0) {
@@ -2099,7 +2099,7 @@ channel_handle_efd_write(struct ssh *ssh, Channel *c,
len = write(c->efd, sshbuf_ptr(c->extended),
sshbuf_len(c->extended));
debug2("channel %d: written %zd to efd %d", c->self, len, c->efd);
- if (len < 0 && (errno == EINTR || errno == EAGAIN ||
+ if (len == -1 && (errno == EINTR || errno == EAGAIN ||
errno == EWOULDBLOCK))
return 1;
if (len <= 0) {
@@ -2130,7 +2130,7 @@ channel_handle_efd_read(struct ssh *ssh, Channel *c,
len = read(c->efd, buf, sizeof(buf));
debug2("channel %d: read %zd from efd %d", c->self, len, c->efd);
- if (len < 0 && (errno == EINTR || ((errno == EAGAIN ||
+ if (len == -1 && (errno == EINTR || ((errno == EAGAIN ||
errno == EWOULDBLOCK) && !force)))
return 1;
if (len <= 0) {
@@ -2219,7 +2219,7 @@ read_mux(struct ssh *ssh, Channel *c, u_int need)
if (sshbuf_len(c->input) < need) {
rlen = need - sshbuf_len(c->input);
len = read(c->rfd, buf, MINIMUM(rlen, CHAN_RBUF));
- if (len < 0 && (errno == EINTR || errno == EAGAIN))
+ if (len == -1 && (errno == EINTR || errno == EAGAIN))
return sshbuf_len(c->input);
if (len <= 0) {
debug2("channel %d: ctl read<=0 rfd %d len %zd",
@@ -2283,7 +2283,7 @@ channel_post_mux_client_write(struct ssh *ssh, Channel *c,
return;
len = write(c->wfd, sshbuf_ptr(c->output), sshbuf_len(c->output));
- if (len < 0 && (errno == EINTR || errno == EAGAIN))
+ if (len == -1 && (errno == EINTR || errno == EAGAIN))
return;
if (len <= 0) {
chan_mark_dead(ssh, c);
@@ -2331,7 +2331,7 @@ channel_post_mux_listener(struct ssh *ssh, Channel *c,
return;
}
- if (getpeereid(newsock, &euid, &egid) < 0) {
+ if (getpeereid(newsock, &euid, &egid) == -1) {
error("%s getpeereid failed: %s", __func__,
strerror(errno));
close(newsock);
@@ -3461,7 +3461,7 @@ channel_setup_fwd_listener_tcpip(struct ssh *ssh, int type,
}
/* Create a port to listen for the host. */
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (sock < 0) {
+ if (sock == -1) {
/* this is no error since kernel may not support ipv6 */
verbose("socket [%s]:%s: %.100s", ntop, strport,
strerror(errno));
@@ -3476,7 +3476,7 @@ channel_setup_fwd_listener_tcpip(struct ssh *ssh, int type,
ntop, strport);
/* Bind the socket to the address. */
- if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
+ if (bind(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
/*
* address can be in if use ipv6 address is
* already bound
@@ -3492,7 +3492,7 @@ channel_setup_fwd_listener_tcpip(struct ssh *ssh, int type,
continue;
}
/* Start listening for connections on the socket. */
- if (listen(sock, SSH_LISTEN_BACKLOG) < 0) {
+ if (listen(sock, SSH_LISTEN_BACKLOG) == -1) {
error("listen: %.100s", strerror(errno));
error("listen [%s]:%s: %.100s", ntop, strport,
strerror(errno));
@@ -4512,7 +4512,7 @@ channel_send_window_changes(struct ssh *ssh)
if (sc->channels[i] == NULL || !sc->channels[i]->client_tty ||
sc->channels[i]->type != SSH_CHANNEL_OPEN)
continue;
- if (ioctl(sc->channels[i]->rfd, TIOCGWINSZ, &ws) < 0)
+ if (ioctl(sc->channels[i]->rfd, TIOCGWINSZ, &ws) == -1)
continue;
channel_request_start(ssh, i, "window-change", 0);
if ((r = sshpkt_put_u32(ssh, (u_int)ws.ws_col)) != 0 ||
@@ -4615,7 +4615,7 @@ x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
continue;
sock = socket(ai->ai_family, ai->ai_socktype,
ai->ai_protocol);
- if (sock < 0) {
+ if (sock == -1) {
if ((errno != EINVAL) && (errno != EAFNOSUPPORT)
#ifdef EPFNOSUPPORT
&& (errno != EPFNOSUPPORT)
@@ -4634,7 +4634,7 @@ x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
sock_set_v6only(sock);
if (x11_use_localhost)
set_reuseaddr(sock);
- if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
+ if (bind(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
debug2("%s: bind port %d: %.100s", __func__,
port, strerror(errno));
close(sock);
@@ -4658,7 +4658,7 @@ x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
/* Start listening for connections on the socket. */
for (n = 0; n < num_socks; n++) {
sock = socks[n];
- if (listen(sock, SSH_LISTEN_BACKLOG) < 0) {
+ if (listen(sock, SSH_LISTEN_BACKLOG) == -1) {
error("listen: %.100s", strerror(errno));
close(sock);
return -1;
@@ -4690,7 +4690,7 @@ connect_local_xsocket_path(const char *pathname)
struct sockaddr_un addr;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0)
+ if (sock == -1)
error("socket: %.100s", strerror(errno));
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
@@ -4831,12 +4831,12 @@ x11_connect_display(struct ssh *ssh)
for (ai = aitop; ai; ai = ai->ai_next) {
/* Create a socket. */
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (sock < 0) {
+ if (sock == -1) {
debug2("socket: %.100s", strerror(errno));
continue;
}
/* Connect it to the display. */
- if (connect(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
+ if (connect(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
debug2("connect %.100s port %u: %.100s", buf,
6000 + display_number, strerror(errno));
close(sock);