Browse Source

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_6_6
deraadt 4 years ago
parent
commit
e5e55cd690
12 changed files with 35 additions and 35 deletions
  1. +4
    -4
      src/lib/libc/hash/helper.c
  2. +2
    -2
      src/lib/libc/stdlib/malloc.c
  3. +4
    -4
      src/lib/libutil/check_expire.c
  4. +2
    -2
      src/lib/libutil/getmaxpartitions.c
  5. +2
    -2
      src/lib/libutil/getrawpartition.c
  6. +2
    -2
      src/lib/libutil/logout.c
  7. +2
    -2
      src/lib/libutil/logwtmp.c
  8. +2
    -2
      src/lib/libutil/passwd.c
  9. +5
    -5
      src/lib/libutil/readlabel.c
  10. +5
    -5
      src/lib/libutil/uucplock.c
  11. +3
    -3
      src/usr.sbin/ntpd/constraint.c
  12. +2
    -2
      src/usr.sbin/ntpd/ntpd.c

+ 4
- 4
src/lib/libc/hash/helper.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: helper.c,v 1.17 2017/10/23 14:33:07 millert Exp $ */
/* $OpenBSD: helper.c,v 1.18 2019/06/28 13:32:41 deraadt Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
@ -67,7 +67,7 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
HASHInit(&ctx);
if ((fd = open(filename, O_RDONLY)) < 0)
if ((fd = open(filename, O_RDONLY)) == -1)
return (NULL);
if (len == 0) {
if (fstat(fd, &sb) == -1) {
@ -78,7 +78,7 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
}
len = sb.st_size;
}
if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
if (off > 0 && lseek(fd, off, SEEK_SET) == -1) {
save_errno = errno;
close(fd);
errno = save_errno;
@ -94,7 +94,7 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
save_errno = errno;
close(fd);
errno = save_errno;
return (nr < 0 ? NULL : HASHEnd(&ctx, buf));
return (nr == -1 ? NULL : HASHEnd(&ctx, buf));
}
DEF_WEAK(HASHFileChunk);


+ 2
- 2
src/lib/libc/stdlib/malloc.c View File

@ -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 <otto@drijf.net>
* Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@ -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);


+ 4
- 4
src/lib/libutil/check_expire.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: check_expire.c,v 1.12 2015/11/26 23:32:52 millert Exp $ */
/* $OpenBSD: check_expire.c,v 1.13 2019/06/28 13:32:43 deraadt Exp $ */
/*
* Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
@ -166,7 +166,7 @@ pwd_update(const struct passwd *pwd, const struct passwd *opwd)
pw_init();
tfd = pw_lock(0);
if (tfd < 0) {
if (tfd == -1) {
if (errno == EEXIST)
return("the passwd file is busy.");
else
@ -174,13 +174,13 @@ pwd_update(const struct passwd *pwd, const struct passwd *opwd)
}
pfd = open(_PATH_MASTERPASSWD, O_RDONLY|O_CLOEXEC, 0);
if (pfd < 0) {
if (pfd == -1) {
pw_abort();
return(strerror(errno));
}
pw_copy(pfd, tfd, pwd, opwd);
if (pw_mkdb(pwd->pw_name, 0) < 0) {
if (pw_mkdb(pwd->pw_name, 0) == -1) {
pw_abort();
return("unable to update password database");
}


+ 2
- 2
src/lib/libutil/getmaxpartitions.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: getmaxpartitions.c,v 1.9 2016/08/27 03:54:20 guenther Exp $ */
/* $OpenBSD: getmaxpartitions.c,v 1.10 2019/06/28 13:32:43 deraadt Exp $ */
/* $NetBSD: getmaxpartitions.c,v 1.1 1996/05/16 07:03:31 thorpej Exp $ */
/*-
@ -45,7 +45,7 @@ getmaxpartitions(void)
mib[0] = CTL_KERN;
mib[1] = KERN_MAXPARTITIONS;
varlen = sizeof(maxpart);
if (sysctl(mib, 2, &maxpart, &varlen, NULL, (size_t)0) < 0)
if (sysctl(mib, 2, &maxpart, &varlen, NULL, (size_t)0) == -1)
return (-1);
return (maxpart);


+ 2
- 2
src/lib/libutil/getrawpartition.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: getrawpartition.c,v 1.9 2016/08/27 03:54:20 guenther Exp $ */
/* $OpenBSD: getrawpartition.c,v 1.10 2019/06/28 13:32:43 deraadt Exp $ */
/* $NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $ */
/*-
@ -45,7 +45,7 @@ getrawpartition(void)
mib[0] = CTL_KERN;
mib[1] = KERN_RAWPARTITION;
varlen = sizeof(rawpart);
if (sysctl(mib, 2, &rawpart, &varlen, NULL, (size_t)0) < 0)
if (sysctl(mib, 2, &rawpart, &varlen, NULL, (size_t)0) == -1)
return (-1);
return (rawpart);


+ 2
- 2
src/lib/libutil/logout.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: logout.c,v 1.9 2015/12/28 20:11:36 guenther Exp $ */
/* $OpenBSD: logout.c,v 1.10 2019/06/28 13:32:43 deraadt Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@ -47,7 +47,7 @@ logout(const char *line)
int fd, rval;
UTMP ut;
if ((fd = open(_PATH_UTMP, O_RDWR|O_CLOEXEC)) < 0)
if ((fd = open(_PATH_UTMP, O_RDWR|O_CLOEXEC)) == -1)
return(0);
rval = 0;
while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {


+ 2
- 2
src/lib/libutil/logwtmp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: logwtmp.c,v 1.10 2016/08/30 14:44:45 guenther Exp $ */
/* $OpenBSD: logwtmp.c,v 1.11 2019/06/28 13:32:43 deraadt Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@ -46,7 +46,7 @@ logwtmp(const char *line, const char *name, const char *host)
struct utmp ut;
int fd;
if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND|O_CLOEXEC)) < 0)
if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND|O_CLOEXEC)) == -1)
return;
if (fstat(fd, &buf) == 0) {
(void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));


+ 2
- 2
src/lib/libutil/passwd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: passwd.c,v 1.55 2018/08/10 17:03:26 deraadt Exp $ */
/* $OpenBSD: passwd.c,v 1.56 2019/06/28 13:32:43 deraadt Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@ -101,7 +101,7 @@ pw_lock(int retries)
/* Acquire the lock file. */
old_mode = umask(0);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600);
for (i = 0; i < retries && fd < 0 && errno == EEXIST; i++) {
for (i = 0; i < retries && fd == -1 && errno == EEXIST; i++) {
sleep(1);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600);
}


+ 5
- 5
src/lib/libutil/readlabel.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: readlabel.c,v 1.14 2016/08/30 14:44:45 guenther Exp $ */
/* $OpenBSD: readlabel.c,v 1.15 2019/06/28 13:32:43 deraadt Exp $ */
/*
* Copyright (c) 1996, Jason Downs. All rights reserved.
@ -74,7 +74,7 @@ readlabelfs(char *device, int verbose)
}
/* Assuming device is of the form /dev/??p, build a raw partition. */
if (stat(device, &sbuf) < 0) {
if (stat(device, &sbuf) == -1) {
if (verbose)
warn("%s", device);
return (NULL);
@ -106,12 +106,12 @@ readlabelfs(char *device, int verbose)
/* If rpath doesn't exist, change that partition back. */
fd = open(rpath, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
if (fd == -1) {
if (errno == ENOENT) {
rpath[strlen(rpath) - 1] = part;
fd = open(rpath, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
if (fd == -1) {
if (verbose)
warn("%s", rpath);
return (NULL);
@ -125,7 +125,7 @@ readlabelfs(char *device, int verbose)
disklabel:
if (ioctl(fd, DIOCGDINFO, &dk) < 0) {
if (ioctl(fd, DIOCGDINFO, &dk) == -1) {
if (verbose)
warn("%s: couldn't read disklabel", rpath);
close(fd);


+ 5
- 5
src/lib/libutil/uucplock.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: uucplock.c,v 1.19 2016/08/30 14:52:09 guenther Exp $ */
/* $OpenBSD: uucplock.c,v 1.20 2019/06/28 13:32:43 deraadt Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@ -71,11 +71,11 @@ uu_lock(const char *ttyname)
(void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT,
ttyname);
tmpfd = open(lcktmpname, O_CREAT|O_TRUNC|O_WRONLY|O_CLOEXEC, 0664);
if (tmpfd < 0)
if (tmpfd == -1)
GORET(0, UU_LOCK_CREAT_ERR);
for (i = 0; i < MAXTRIES; i++) {
if (link(lcktmpname, lckname) < 0) {
if (link(lcktmpname, lckname) == -1) {
if (errno != EEXIST)
GORET(1, UU_LOCK_LINK_ERR);
/*
@ -83,7 +83,7 @@ uu_lock(const char *ttyname)
* check to see if the process holding the lock
* still exists
*/
if ((fd = open(lckname, O_RDONLY | O_CLOEXEC)) < 0)
if ((fd = open(lckname, O_RDONLY | O_CLOEXEC)) == -1)
GORET(1, UU_LOCK_OPEN_ERR);
if ((pid_old = get_pid(fd, &err)) == -1)
@ -127,7 +127,7 @@ uu_lock_txfr(const char *ttyname, pid_t pid)
snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname);
if ((fd = open(lckname, O_RDWR | O_CLOEXEC)) < 0)
if ((fd = open(lckname, O_RDWR | O_CLOEXEC)) == -1)
return UU_LOCK_OWNER_ERR;
if (get_pid(fd, &err) != getpid())
ret = UU_LOCK_OWNER_ERR;


+ 3
- 3
src/usr.sbin/ntpd/constraint.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: constraint.c,v 1.46 2019/06/16 07:36:25 otto Exp $ */
/* $OpenBSD: constraint.c,v 1.47 2019/06/28 13:32:49 deraadt Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@ -955,7 +955,7 @@ httpsdate_request(struct httpsdate *httpsdate, struct timeval *when)
ret = tls_write(httpsdate->tls_ctx, buf, len);
if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
continue;
if (ret < 0) {
if (ret == -1) {
log_warnx("tls write failed: %s (%s): %s",
httpsdate->tls_addr, httpsdate->tls_hostname,
tls_error(httpsdate->tls_ctx));
@ -1091,7 +1091,7 @@ tls_readline(struct tls *tls, size_t *lenp, size_t *maxlength,
ret = tls_read(tls, &c, 1);
if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
goto again;
if (ret < 0) {
if (ret == -1) {
/* SSL read error, ignore */
free(buf);
return (NULL);


+ 2
- 2
src/usr.sbin/ntpd/ntpd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.123 2019/06/27 15:18:42 otto Exp $ */
/* $OpenBSD: ntpd.c,v 1.124 2019/06/28 13:32:49 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -111,7 +111,7 @@ auto_preconditions(const struct ntpd_conf *cnf)
int constraints, securelevel;
size_t sz = sizeof(int);
if (sysctl(mib, 2, &securelevel, &sz, NULL, 0) < 0)
if (sysctl(mib, 2, &securelevel, &sz, NULL, 0) == -1)
err(1, "sysctl");
constraints = !TAILQ_EMPTY(&cnf->constraints);
return !cnf->settime && constraints && securelevel == 0;


Loading…
Cancel
Save