From 835d788017c49be8b4986b0f04686da55f2cd0da Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Fri, 28 Jun 2019 13:35:02 +0000 Subject: 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. --- src/lib/libc/net/rcmdsh.c | 10 +++++----- src/lib/libc/net/rresvport.c | 6 +++--- src/lib/libc/net/ruserok.c | 4 ++-- src/lib/libc/stdlib/malloc.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/lib/libc') 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 @@ -/* $OpenBSD: rcmdsh.c,v 1.19 2016/05/28 15:46:00 millert Exp $ */ +/* $OpenBSD: rcmdsh.c,v 1.20 2019/06/28 13:32:42 deraadt Exp $ */ /* * Copyright (c) 2001, MagniComp @@ -89,13 +89,13 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, } /* Get a socketpair we'll use for stdin and stdout. */ - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) < 0) { + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) == -1) { perror("rcmdsh: socketpair"); return(-1); } cpid = fork(); - if (cpid < 0) { + if (cpid == -1) { perror("rcmdsh: fork failed"); return(-1); } else if (cpid == 0) { @@ -103,13 +103,13 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, * Child. We use sp[1] to be stdin/stdout, and close sp[0]. */ (void) close(sp[0]); - if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) { + if (dup2(sp[1], 0) == -1 || dup2(0, 1) == -1) { perror("rcmdsh: dup2 failed"); _exit(255); } /* Fork again to lose parent. */ cpid = fork(); - if (cpid < 0) { + if (cpid == -1) { perror("rcmdsh: fork to lose parent failed"); _exit(255); } 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 @@ -/* $OpenBSD: rresvport.c,v 1.11 2015/09/12 14:56:50 guenther Exp $ */ +/* $OpenBSD: rresvport.c,v 1.12 2019/06/28 13:32:42 deraadt Exp $ */ /* * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. * Copyright (c) 1983, 1993, 1994 @@ -82,12 +82,12 @@ rresvport_af(int *alport, int af) sa->sa_family = af; s = socket(af, SOCK_STREAM, 0); - if (s < 0) + if (s == -1) return (-1); *portp = htons(*alport); if (*alport < IPPORT_RESERVED - 1) { - if (bind(s, sa, sa->sa_len) >= 0) + if (bind(s, sa, sa->sa_len) != -1) return (s); if (errno != EADDRINUSE) { (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: * user or root or if writeable by anyone but the owner, quit. */ cp = NULL; - if (lstat(pbuf, &sbuf) < 0) + if (lstat(pbuf, &sbuf) == -1) cp = ".rhosts lstat failed"; else if (!S_ISREG(sbuf.st_mode)) cp = ".rhosts not regular file"; - else if (fstat(fileno(hostf), &sbuf) < 0) + else if (fstat(fileno(hostf), &sbuf) == -1) cp = ".rhosts fstat failed"; else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) 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 @@ -/* $OpenBSD: malloc.c,v 1.261 2019/05/23 06:43:18 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.262 2019/06/28 13:32:42 deraadt Exp $ */ /* * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky @@ -897,7 +897,7 @@ omalloc_make_chunks(struct dir_info *d, int bits, int listnum) return NULL; /* memory protect the page allocated in the malloc(0) case */ - if (bits == 0 && mprotect(pp, MALLOC_PAGESIZE, PROT_NONE) < 0) + if (bits == 0 && mprotect(pp, MALLOC_PAGESIZE, PROT_NONE) == -1) goto err; bp = alloc_chunk_info(d, bits); -- cgit v1.2.3-55-g6feb