From 86ffccf24f66032a89d70a32b3609584c0db7345 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Fri, 28 Jun 2019 13:32:54 +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. --- libexec/mail.local/mail.local.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libexec/mail.local') diff --git a/libexec/mail.local/mail.local.c b/libexec/mail.local/mail.local.c index b823ab0d83b..ddfaae20a0a 100644 --- a/libexec/mail.local/mail.local.c +++ b/libexec/mail.local/mail.local.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mail.local.c,v 1.35 2015/12/12 20:09:28 mmcc Exp $ */ +/* $OpenBSD: mail.local.c,v 1.36 2019/06/28 13:32:53 deraadt Exp $ */ /*- * Copyright (c) 1996-1998 Theo de Raadt @@ -201,7 +201,7 @@ retry: goto bad; } if ((mbfd = open(path, O_APPEND|O_CREAT|O_EXCL|O_WRONLY|O_EXLOCK, - S_IRUSR|S_IWUSR)) < 0) { + S_IRUSR|S_IWUSR)) == -1) { if (errno == EEXIST) { /* file appeared since lstat */ goto retry; @@ -216,7 +216,7 @@ retry: * that if the ownership or permissions were changed there * was a reason for doing so. */ - if (fchown(mbfd, pw->pw_uid, pw->pw_gid) < 0) { + if (fchown(mbfd, pw->pw_uid, pw->pw_gid) == -1) { merr(NOTFATAL, "chown %u:%u: %s", pw->pw_uid, pw->pw_gid, name); goto bad; @@ -227,11 +227,11 @@ retry: goto bad; } if ((mbfd = open(path, O_APPEND|O_WRONLY|O_EXLOCK, - S_IRUSR|S_IWUSR)) < 0) { + S_IRUSR|S_IWUSR)) == -1) { merr(NOTFATAL, "%s: %s", path, strerror(errno)); goto bad; } - if (fstat(mbfd, &fsb)) { + if (fstat(mbfd, &fsb) == -1) { /* relating error to path may be bad style */ merr(NOTFATAL, "%s: %s", path, strerror(errno)); goto bad; @@ -256,7 +256,7 @@ retry: while ((nr = read(fd, buf, sizeof(buf))) > 0) for (off = 0; off < nr; off += nw) - if ((nw = write(mbfd, buf + off, nr - off)) < 0) { + if ((nw = write(mbfd, buf + off, nr - off)) == -1) { merr(NOTFATAL, "%s: %s", path, strerror(errno)); (void)ftruncate(mbfd, curoff); goto bad; -- cgit v1.2.3