summaryrefslogtreecommitdiff
path: root/packet.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 /packet.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 'packet.c')
-rw-r--r--packet.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/packet.c b/packet.c
index 8333c7ca9..817da43b5 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.285 2019/06/07 14:18:48 dtucker Exp $ */ 1/* $OpenBSD: packet.c,v 1.286 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
@@ -440,12 +440,12 @@ ssh_packet_connection_is_on_socket(struct ssh *ssh)
440 fromlen = sizeof(from); 440 fromlen = sizeof(from);
441 memset(&from, 0, sizeof(from)); 441 memset(&from, 0, sizeof(from));
442 if (getpeername(state->connection_in, (struct sockaddr *)&from, 442 if (getpeername(state->connection_in, (struct sockaddr *)&from,
443 &fromlen) < 0) 443 &fromlen) == -1)
444 return 0; 444 return 0;
445 tolen = sizeof(to); 445 tolen = sizeof(to);
446 memset(&to, 0, sizeof(to)); 446 memset(&to, 0, sizeof(to));
447 if (getpeername(state->connection_out, (struct sockaddr *)&to, 447 if (getpeername(state->connection_out, (struct sockaddr *)&to,
448 &tolen) < 0) 448 &tolen) == -1)
449 return 0; 449 return 0;
450 if (fromlen != tolen || memcmp(&from, &to, fromlen) != 0) 450 if (fromlen != tolen || memcmp(&from, &to, fromlen) != 0)
451 return 0; 451 return 0;
@@ -471,7 +471,7 @@ ssh_packet_connection_af(struct ssh *ssh)
471 471
472 memset(&to, 0, sizeof(to)); 472 memset(&to, 0, sizeof(to));
473 if (getsockname(ssh->state->connection_out, (struct sockaddr *)&to, 473 if (getsockname(ssh->state->connection_out, (struct sockaddr *)&to,
474 &tolen) < 0) 474 &tolen) == -1)
475 return 0; 475 return 0;
476#ifdef IPV4_IN_IPV6 476#ifdef IPV4_IN_IPV6
477 if (to.ss_family == AF_INET6 && 477 if (to.ss_family == AF_INET6 &&
@@ -1359,7 +1359,7 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
1359 r = SSH_ERR_CONN_CLOSED; 1359 r = SSH_ERR_CONN_CLOSED;
1360 goto out; 1360 goto out;
1361 } 1361 }
1362 if (len < 0) { 1362 if (len == -1) {
1363 r = SSH_ERR_SYSTEM_ERROR; 1363 r = SSH_ERR_SYSTEM_ERROR;
1364 goto out; 1364 goto out;
1365 } 1365 }
@@ -2036,7 +2036,7 @@ ssh_packet_set_tos(struct ssh *ssh, int tos)
2036 case AF_INET: 2036 case AF_INET:
2037 debug3("%s: set IP_TOS 0x%02x", __func__, tos); 2037 debug3("%s: set IP_TOS 0x%02x", __func__, tos);
2038 if (setsockopt(ssh->state->connection_in, 2038 if (setsockopt(ssh->state->connection_in,
2039 IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) 2039 IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
2040 error("setsockopt IP_TOS %d: %.100s:", 2040 error("setsockopt IP_TOS %d: %.100s:",
2041 tos, strerror(errno)); 2041 tos, strerror(errno));
2042 break; 2042 break;
@@ -2045,7 +2045,7 @@ ssh_packet_set_tos(struct ssh *ssh, int tos)
2045 case AF_INET6: 2045 case AF_INET6:
2046 debug3("%s: set IPV6_TCLASS 0x%02x", __func__, tos); 2046 debug3("%s: set IPV6_TCLASS 0x%02x", __func__, tos);
2047 if (setsockopt(ssh->state->connection_in, 2047 if (setsockopt(ssh->state->connection_in,
2048 IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)) < 0) 2048 IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)) == -1)
2049 error("setsockopt IPV6_TCLASS %d: %.100s:", 2049 error("setsockopt IPV6_TCLASS %d: %.100s:",
2050 tos, strerror(errno)); 2050 tos, strerror(errno));
2051 break; 2051 break;