diff options
author | deraadt@openbsd.org <deraadt@openbsd.org> | 2019-06-28 13:35:04 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-07-05 11:10:39 +1000 |
commit | 4d28fa78abce2890e136281950633fae2066cc29 (patch) | |
tree | 33226ec64ced661bb7e40005e30744b68fa59a80 /misc.c | |
parent | e8c974043c1648eab0ad67a7ba6a3e444fe79d2d (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 'misc.c')
-rw-r--r-- | misc.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.138 2019/06/27 18:03:37 deraadt Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.139 2019/06/28 13:35:04 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -96,7 +96,7 @@ set_nonblock(int fd) | |||
96 | int val; | 96 | int val; |
97 | 97 | ||
98 | val = fcntl(fd, F_GETFL); | 98 | val = fcntl(fd, F_GETFL); |
99 | if (val < 0) { | 99 | if (val == -1) { |
100 | error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); | 100 | error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
101 | return (-1); | 101 | return (-1); |
102 | } | 102 | } |
@@ -120,7 +120,7 @@ unset_nonblock(int fd) | |||
120 | int val; | 120 | int val; |
121 | 121 | ||
122 | val = fcntl(fd, F_GETFL); | 122 | val = fcntl(fd, F_GETFL); |
123 | if (val < 0) { | 123 | if (val == -1) { |
124 | error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); | 124 | error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
125 | return (-1); | 125 | return (-1); |
126 | } | 126 | } |
@@ -1136,7 +1136,7 @@ tun_open(int tun, int mode, char **ifname) | |||
1136 | return -1; | 1136 | return -1; |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | if (fd < 0) { | 1139 | if (fd == -1) { |
1140 | debug("%s: %s open: %s", __func__, name, strerror(errno)); | 1140 | debug("%s: %s open: %s", __func__, name, strerror(errno)); |
1141 | return -1; | 1141 | return -1; |
1142 | } | 1142 | } |
@@ -1575,7 +1575,7 @@ unix_listener(const char *path, int backlog, int unlink_first) | |||
1575 | } | 1575 | } |
1576 | 1576 | ||
1577 | sock = socket(PF_UNIX, SOCK_STREAM, 0); | 1577 | sock = socket(PF_UNIX, SOCK_STREAM, 0); |
1578 | if (sock < 0) { | 1578 | if (sock == -1) { |
1579 | saved_errno = errno; | 1579 | saved_errno = errno; |
1580 | error("%s: socket: %.100s", __func__, strerror(errno)); | 1580 | error("%s: socket: %.100s", __func__, strerror(errno)); |
1581 | errno = saved_errno; | 1581 | errno = saved_errno; |
@@ -1585,7 +1585,7 @@ unix_listener(const char *path, int backlog, int unlink_first) | |||
1585 | if (unlink(path) != 0 && errno != ENOENT) | 1585 | if (unlink(path) != 0 && errno != ENOENT) |
1586 | error("unlink(%s): %.100s", path, strerror(errno)); | 1586 | error("unlink(%s): %.100s", path, strerror(errno)); |
1587 | } | 1587 | } |
1588 | if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) { | 1588 | if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1) { |
1589 | saved_errno = errno; | 1589 | saved_errno = errno; |
1590 | error("%s: cannot bind to path %s: %s", | 1590 | error("%s: cannot bind to path %s: %s", |
1591 | __func__, path, strerror(errno)); | 1591 | __func__, path, strerror(errno)); |
@@ -1593,7 +1593,7 @@ unix_listener(const char *path, int backlog, int unlink_first) | |||
1593 | errno = saved_errno; | 1593 | errno = saved_errno; |
1594 | return -1; | 1594 | return -1; |
1595 | } | 1595 | } |
1596 | if (listen(sock, backlog) < 0) { | 1596 | if (listen(sock, backlog) == -1) { |
1597 | saved_errno = errno; | 1597 | saved_errno = errno; |
1598 | error("%s: cannot listen on path %s: %s", | 1598 | error("%s: cannot listen on path %s: %s", |
1599 | __func__, path, strerror(errno)); | 1599 | __func__, path, strerror(errno)); |
@@ -1875,7 +1875,7 @@ safe_path(const char *name, struct stat *stp, const char *pw_dir, | |||
1875 | } | 1875 | } |
1876 | strlcpy(buf, cp, sizeof(buf)); | 1876 | strlcpy(buf, cp, sizeof(buf)); |
1877 | 1877 | ||
1878 | if (stat(buf, &st) < 0 || | 1878 | if (stat(buf, &st) == -1 || |
1879 | (!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) || | 1879 | (!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) || |
1880 | (st.st_mode & 022) != 0) { | 1880 | (st.st_mode & 022) != 0) { |
1881 | snprintf(err, errlen, | 1881 | snprintf(err, errlen, |
@@ -1910,7 +1910,7 @@ safe_path_fd(int fd, const char *file, struct passwd *pw, | |||
1910 | struct stat st; | 1910 | struct stat st; |
1911 | 1911 | ||
1912 | /* check the open file to avoid races */ | 1912 | /* check the open file to avoid races */ |
1913 | if (fstat(fd, &st) < 0) { | 1913 | if (fstat(fd, &st) == -1) { |
1914 | snprintf(err, errlen, "cannot stat file %s: %s", | 1914 | snprintf(err, errlen, "cannot stat file %s: %s", |
1915 | file, strerror(errno)); | 1915 | file, strerror(errno)); |
1916 | return -1; | 1916 | return -1; |