diff options
author | deraadt <> | 2019-06-28 13:35:02 +0000 |
---|---|---|
committer | deraadt <> | 2019-06-28 13:35:02 +0000 |
commit | 6585927e66d9ab172754d95c4296dd4309a40512 (patch) | |
tree | bc969c069c7b769f2601db17f08bec99274202a5 /src/lib | |
parent | 74ff76124ba7a371400a9f60d5e33192a3732f03 (diff) | |
download | openbsd-6585927e66d9ab172754d95c4296dd4309a40512.tar.gz openbsd-6585927e66d9ab172754d95c4296dd4309a40512.tar.bz2 openbsd-6585927e66d9ab172754d95c4296dd4309a40512.zip |
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.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/rcmdsh.c | 10 | ||||
-rw-r--r-- | src/lib/libc/net/rresvport.c | 6 | ||||
-rw-r--r-- | src/lib/libc/net/ruserok.c | 4 | ||||
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 4 |
4 files changed, 12 insertions, 12 deletions
diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c index b9cbd6d5d1..66caac3f3d 100644 --- a/src/lib/libc/net/rcmdsh.c +++ b/src/lib/libc/net/rcmdsh.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rcmdsh.c,v 1.19 2016/05/28 15:46:00 millert Exp $ */ | 1 | /* $OpenBSD: rcmdsh.c,v 1.20 2019/06/28 13:32:42 deraadt Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001, MagniComp | 4 | * Copyright (c) 2001, MagniComp |
@@ -89,13 +89,13 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, | |||
89 | } | 89 | } |
90 | 90 | ||
91 | /* Get a socketpair we'll use for stdin and stdout. */ | 91 | /* Get a socketpair we'll use for stdin and stdout. */ |
92 | if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) < 0) { | 92 | if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) == -1) { |
93 | perror("rcmdsh: socketpair"); | 93 | perror("rcmdsh: socketpair"); |
94 | return(-1); | 94 | return(-1); |
95 | } | 95 | } |
96 | 96 | ||
97 | cpid = fork(); | 97 | cpid = fork(); |
98 | if (cpid < 0) { | 98 | if (cpid == -1) { |
99 | perror("rcmdsh: fork failed"); | 99 | perror("rcmdsh: fork failed"); |
100 | return(-1); | 100 | return(-1); |
101 | } else if (cpid == 0) { | 101 | } else if (cpid == 0) { |
@@ -103,13 +103,13 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, | |||
103 | * Child. We use sp[1] to be stdin/stdout, and close sp[0]. | 103 | * Child. We use sp[1] to be stdin/stdout, and close sp[0]. |
104 | */ | 104 | */ |
105 | (void) close(sp[0]); | 105 | (void) close(sp[0]); |
106 | if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) { | 106 | if (dup2(sp[1], 0) == -1 || dup2(0, 1) == -1) { |
107 | perror("rcmdsh: dup2 failed"); | 107 | perror("rcmdsh: dup2 failed"); |
108 | _exit(255); | 108 | _exit(255); |
109 | } | 109 | } |
110 | /* Fork again to lose parent. */ | 110 | /* Fork again to lose parent. */ |
111 | cpid = fork(); | 111 | cpid = fork(); |
112 | if (cpid < 0) { | 112 | if (cpid == -1) { |
113 | perror("rcmdsh: fork to lose parent failed"); | 113 | perror("rcmdsh: fork to lose parent failed"); |
114 | _exit(255); | 114 | _exit(255); |
115 | } | 115 | } |
diff --git a/src/lib/libc/net/rresvport.c b/src/lib/libc/net/rresvport.c index 6b45000f7b..72c27c3a3f 100644 --- a/src/lib/libc/net/rresvport.c +++ b/src/lib/libc/net/rresvport.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rresvport.c,v 1.11 2015/09/12 14:56:50 guenther Exp $ */ | 1 | /* $OpenBSD: rresvport.c,v 1.12 2019/06/28 13:32:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. | 3 | * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. |
4 | * Copyright (c) 1983, 1993, 1994 | 4 | * Copyright (c) 1983, 1993, 1994 |
@@ -82,12 +82,12 @@ rresvport_af(int *alport, int af) | |||
82 | sa->sa_family = af; | 82 | sa->sa_family = af; |
83 | 83 | ||
84 | s = socket(af, SOCK_STREAM, 0); | 84 | s = socket(af, SOCK_STREAM, 0); |
85 | if (s < 0) | 85 | if (s == -1) |
86 | return (-1); | 86 | return (-1); |
87 | 87 | ||
88 | *portp = htons(*alport); | 88 | *portp = htons(*alport); |
89 | if (*alport < IPPORT_RESERVED - 1) { | 89 | if (*alport < IPPORT_RESERVED - 1) { |
90 | if (bind(s, sa, sa->sa_len) >= 0) | 90 | if (bind(s, sa, sa->sa_len) != -1) |
91 | return (s); | 91 | return (s); |
92 | if (errno != EADDRINUSE) { | 92 | if (errno != EADDRINUSE) { |
93 | (void)close(s); | 93 | (void)close(s); |
diff --git a/src/lib/libc/net/ruserok.c b/src/lib/libc/net/ruserok.c index cab6f96449..a399c013e2 100644 --- a/src/lib/libc/net/ruserok.c +++ b/src/lib/libc/net/ruserok.c | |||
@@ -131,11 +131,11 @@ again: | |||
131 | * user or root or if writeable by anyone but the owner, quit. | 131 | * user or root or if writeable by anyone but the owner, quit. |
132 | */ | 132 | */ |
133 | cp = NULL; | 133 | cp = NULL; |
134 | if (lstat(pbuf, &sbuf) < 0) | 134 | if (lstat(pbuf, &sbuf) == -1) |
135 | cp = ".rhosts lstat failed"; | 135 | cp = ".rhosts lstat failed"; |
136 | else if (!S_ISREG(sbuf.st_mode)) | 136 | else if (!S_ISREG(sbuf.st_mode)) |
137 | cp = ".rhosts not regular file"; | 137 | cp = ".rhosts not regular file"; |
138 | else if (fstat(fileno(hostf), &sbuf) < 0) | 138 | else if (fstat(fileno(hostf), &sbuf) == -1) |
139 | cp = ".rhosts fstat failed"; | 139 | cp = ".rhosts fstat failed"; |
140 | else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) | 140 | else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) |
141 | cp = "bad .rhosts owner"; | 141 | cp = "bad .rhosts owner"; |
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index f2e82679e9..7d49438b7b 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.261 2019/05/23 06:43:18 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.262 2019/06/28 13:32:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
@@ -897,7 +897,7 @@ omalloc_make_chunks(struct dir_info *d, int bits, int listnum) | |||
897 | return NULL; | 897 | return NULL; |
898 | 898 | ||
899 | /* memory protect the page allocated in the malloc(0) case */ | 899 | /* memory protect the page allocated in the malloc(0) case */ |
900 | if (bits == 0 && mprotect(pp, MALLOC_PAGESIZE, PROT_NONE) < 0) | 900 | if (bits == 0 && mprotect(pp, MALLOC_PAGESIZE, PROT_NONE) == -1) |
901 | goto err; | 901 | goto err; |
902 | 902 | ||
903 | bp = alloc_chunk_info(d, bits); | 903 | bp = alloc_chunk_info(d, bits); |