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)
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 2dc500b47..ed44fccb8 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.316 2019/06/21 04:21:04 djm Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.317 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
@@ -133,7 +133,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
133 if ((shell = getenv("SHELL")) == NULL) 133 if ((shell = getenv("SHELL")) == NULL)
134 shell = _PATH_BSHELL; 134 shell = _PATH_BSHELL;
135 135
136 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) < 0) 136 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) == -1)
137 fatal("Could not create socketpair to communicate with " 137 fatal("Could not create socketpair to communicate with "
138 "proxy dialer: %.100s", strerror(errno)); 138 "proxy dialer: %.100s", strerror(errno));
139 139
@@ -148,11 +148,11 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
148 close(sp[1]); 148 close(sp[1]);
149 /* Redirect stdin and stdout. */ 149 /* Redirect stdin and stdout. */
150 if (sp[0] != 0) { 150 if (sp[0] != 0) {
151 if (dup2(sp[0], 0) < 0) 151 if (dup2(sp[0], 0) == -1)
152 perror("dup2 stdin"); 152 perror("dup2 stdin");
153 } 153 }
154 if (sp[0] != 1) { 154 if (sp[0] != 1) {
155 if (dup2(sp[0], 1) < 0) 155 if (dup2(sp[0], 1) == -1)
156 perror("dup2 stdout"); 156 perror("dup2 stdout");
157 } 157 }
158 if (sp[0] >= 2) 158 if (sp[0] >= 2)
@@ -180,7 +180,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
180 exit(1); 180 exit(1);
181 } 181 }
182 /* Parent. */ 182 /* Parent. */
183 if (pid < 0) 183 if (pid == -1)
184 fatal("fork failed: %.100s", strerror(errno)); 184 fatal("fork failed: %.100s", strerror(errno));
185 close(sp[0]); 185 close(sp[0]);
186 free(command_string); 186 free(command_string);
@@ -216,7 +216,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
216 shell = _PATH_BSHELL; 216 shell = _PATH_BSHELL;
217 217
218 /* Create pipes for communicating with the proxy. */ 218 /* Create pipes for communicating with the proxy. */
219 if (pipe(pin) < 0 || pipe(pout) < 0) 219 if (pipe(pin) == -1 || pipe(pout) == -1)
220 fatal("Could not create pipes to communicate with the proxy: %.100s", 220 fatal("Could not create pipes to communicate with the proxy: %.100s",
221 strerror(errno)); 221 strerror(errno));
222 222
@@ -231,12 +231,12 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
231 /* Redirect stdin and stdout. */ 231 /* Redirect stdin and stdout. */
232 close(pin[1]); 232 close(pin[1]);
233 if (pin[0] != 0) { 233 if (pin[0] != 0) {
234 if (dup2(pin[0], 0) < 0) 234 if (dup2(pin[0], 0) == -1)
235 perror("dup2 stdin"); 235 perror("dup2 stdin");
236 close(pin[0]); 236 close(pin[0]);
237 } 237 }
238 close(pout[0]); 238 close(pout[0]);
239 if (dup2(pout[1], 1) < 0) 239 if (dup2(pout[1], 1) == -1)
240 perror("dup2 stdout"); 240 perror("dup2 stdout");
241 /* Cannot be 1 because pin allocated two descriptors. */ 241 /* Cannot be 1 because pin allocated two descriptors. */
242 close(pout[1]); 242 close(pout[1]);
@@ -262,7 +262,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
262 exit(1); 262 exit(1);
263 } 263 }
264 /* Parent. */ 264 /* Parent. */
265 if (pid < 0) 265 if (pid == -1)
266 fatal("fork failed: %.100s", strerror(errno)); 266 fatal("fork failed: %.100s", strerror(errno));
267 else 267 else
268 proxy_command_pid = pid; /* save pid to clean up later */ 268 proxy_command_pid = pid; /* save pid to clean up later */
@@ -371,7 +371,7 @@ ssh_create_socket(struct addrinfo *ai)
371 char ntop[NI_MAXHOST]; 371 char ntop[NI_MAXHOST];
372 372
373 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); 373 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
374 if (sock < 0) { 374 if (sock == -1) {
375 error("socket: %s", strerror(errno)); 375 error("socket: %s", strerror(errno));
376 return -1; 376 return -1;
377 } 377 }
@@ -532,7 +532,7 @@ ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop,
532 /* Set SO_KEEPALIVE if requested. */ 532 /* Set SO_KEEPALIVE if requested. */
533 if (want_keepalive && 533 if (want_keepalive &&
534 setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, 534 setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,
535 sizeof(on)) < 0) 535 sizeof(on)) == -1)
536 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); 536 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
537 537
538 /* Set the connection. */ 538 /* Set the connection. */
@@ -553,8 +553,8 @@ ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs,
553 return ssh_connect_direct(ssh, host, addrs, hostaddr, port, 553 return ssh_connect_direct(ssh, host, addrs, hostaddr, port,
554 family, connection_attempts, timeout_ms, want_keepalive); 554 family, connection_attempts, timeout_ms, want_keepalive);
555 } else if (strcmp(options.proxy_command, "-") == 0) { 555 } else if (strcmp(options.proxy_command, "-") == 0) {
556 if ((in = dup(STDIN_FILENO)) < 0 || 556 if ((in = dup(STDIN_FILENO)) == -1 ||
557 (out = dup(STDOUT_FILENO)) < 0) { 557 (out = dup(STDOUT_FILENO)) == -1) {
558 if (in >= 0) 558 if (in >= 0)
559 close(in); 559 close(in);
560 error("%s: dup() in/out failed", __func__); 560 error("%s: dup() in/out failed", __func__);