summaryrefslogtreecommitdiff
path: root/sshconnect.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 /sshconnect.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 'sshconnect.c')
-rw-r--r--sshconnect.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/sshconnect.c b/sshconnect.c
index 2dc500b4..ed44fccb 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect.c,v 1.316 2019/06/21 04:21:04 djm Exp $ */
+/* $OpenBSD: sshconnect.c,v 1.317 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
@@ -133,7 +133,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
if ((shell = getenv("SHELL")) == NULL)
shell = _PATH_BSHELL;
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) < 0)
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) == -1)
fatal("Could not create socketpair to communicate with "
"proxy dialer: %.100s", strerror(errno));
@@ -148,11 +148,11 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
close(sp[1]);
/* Redirect stdin and stdout. */
if (sp[0] != 0) {
- if (dup2(sp[0], 0) < 0)
+ if (dup2(sp[0], 0) == -1)
perror("dup2 stdin");
}
if (sp[0] != 1) {
- if (dup2(sp[0], 1) < 0)
+ if (dup2(sp[0], 1) == -1)
perror("dup2 stdout");
}
if (sp[0] >= 2)
@@ -180,7 +180,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
exit(1);
}
/* Parent. */
- if (pid < 0)
+ if (pid == -1)
fatal("fork failed: %.100s", strerror(errno));
close(sp[0]);
free(command_string);
@@ -216,7 +216,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
shell = _PATH_BSHELL;
/* Create pipes for communicating with the proxy. */
- if (pipe(pin) < 0 || pipe(pout) < 0)
+ if (pipe(pin) == -1 || pipe(pout) == -1)
fatal("Could not create pipes to communicate with the proxy: %.100s",
strerror(errno));
@@ -231,12 +231,12 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
/* Redirect stdin and stdout. */
close(pin[1]);
if (pin[0] != 0) {
- if (dup2(pin[0], 0) < 0)
+ if (dup2(pin[0], 0) == -1)
perror("dup2 stdin");
close(pin[0]);
}
close(pout[0]);
- if (dup2(pout[1], 1) < 0)
+ if (dup2(pout[1], 1) == -1)
perror("dup2 stdout");
/* Cannot be 1 because pin allocated two descriptors. */
close(pout[1]);
@@ -262,7 +262,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
exit(1);
}
/* Parent. */
- if (pid < 0)
+ if (pid == -1)
fatal("fork failed: %.100s", strerror(errno));
else
proxy_command_pid = pid; /* save pid to clean up later */
@@ -371,7 +371,7 @@ ssh_create_socket(struct addrinfo *ai)
char ntop[NI_MAXHOST];
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (sock < 0) {
+ if (sock == -1) {
error("socket: %s", strerror(errno));
return -1;
}
@@ -532,7 +532,7 @@ ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop,
/* Set SO_KEEPALIVE if requested. */
if (want_keepalive &&
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,
- sizeof(on)) < 0)
+ sizeof(on)) == -1)
error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
/* Set the connection. */
@@ -553,8 +553,8 @@ ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs,
return ssh_connect_direct(ssh, host, addrs, hostaddr, port,
family, connection_attempts, timeout_ms, want_keepalive);
} else if (strcmp(options.proxy_command, "-") == 0) {
- if ((in = dup(STDIN_FILENO)) < 0 ||
- (out = dup(STDOUT_FILENO)) < 0) {
+ if ((in = dup(STDIN_FILENO)) == -1 ||
+ (out = dup(STDOUT_FILENO)) == -1) {
if (in >= 0)
close(in);
error("%s: dup() in/out failed", __func__);