From df69c215c7c66baf660f3f65414fd34796c96152 Mon Sep 17 00:00:00 2001 From: deraadt Date: Fri, 28 Jun 2019 13:32:41 +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. --- usr.sbin/syslogd/evbuffer_tls.c | 4 ++-- usr.sbin/syslogd/privsep.c | 16 ++++++++-------- usr.sbin/syslogd/syslogd.c | 12 ++++++------ usr.sbin/syslogd/ttymsg.c | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'usr.sbin/syslogd') diff --git a/usr.sbin/syslogd/evbuffer_tls.c b/usr.sbin/syslogd/evbuffer_tls.c index 9a0f8daecf1..3fa75c499a2 100644 --- a/usr.sbin/syslogd/evbuffer_tls.c +++ b/usr.sbin/syslogd/evbuffer_tls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evbuffer_tls.c,v 1.11 2017/07/04 15:52:26 bluhm Exp $ */ +/* $OpenBSD: evbuffer_tls.c,v 1.12 2019/06/28 13:32:51 deraadt Exp $ */ /* * Copyright (c) 2002-2004 Niels Provos @@ -229,7 +229,7 @@ buffertls_handshakecb(int fd, short event, void *arg) what |= EVBUFFER_ERROR; break; } - if (res < 0) + if (res == -1) goto error; /* Handshake was successful, change to read and write callback. */ diff --git a/usr.sbin/syslogd/privsep.c b/usr.sbin/syslogd/privsep.c index 45463dbe703..1da7f4f46bd 100644 --- a/usr.sbin/syslogd/privsep.c +++ b/usr.sbin/syslogd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.69 2018/08/07 18:36:49 deraadt Exp $ */ +/* $OpenBSD: privsep.c,v 1.70 2019/06/28 13:32:51 deraadt Exp $ */ /* * Copyright (c) 2003 Anil Madhavapeddy @@ -110,7 +110,7 @@ priv_init(int lockfd, int nullfd, int argc, char *argv[]) errx(1, "unknown user _syslogd"); child_pid = fork(); - if (child_pid < 0) + if (child_pid == -1) err(1, "fork() failed"); if (!child_pid) { @@ -239,7 +239,7 @@ priv_exec(char *conf, int numeric, int child, int argc, char *argv[]) if (sigprocmask(SIG_SETMASK, &sigmask, NULL) == -1) err(1, "sigprocmask priv"); - if (stat(conf, &cf_info) < 0) + if (stat(conf, &cf_info) == -1) err(1, "stat config file failed"); TAILQ_INIT(&lognames); @@ -261,7 +261,7 @@ priv_exec(char *conf, int numeric, int child, int argc, char *argv[]) check_tty_name(path, sizeof(path)); fd = open(path, O_WRONLY|O_NONBLOCK, 0); send_fd(sock, fd); - if (fd < 0) + if (fd == -1) warnx("priv_open_tty failed"); else close(fd); @@ -287,7 +287,7 @@ priv_exec(char *conf, int numeric, int child, int argc, char *argv[]) errx(1, "invalid cmd"); send_fd(sock, fd); - if (fd < 0) + if (fd == -1) warnx("priv_open_log failed"); else close(fd); @@ -297,7 +297,7 @@ priv_exec(char *conf, int numeric, int child, int argc, char *argv[]) log_debug("[priv]: msg PRIV_OPEN_UTMP received"); fd = open(_PATH_UTMP, O_RDONLY|O_NONBLOCK, 0); send_fd(sock, fd); - if (fd < 0) + if (fd == -1) warnx("priv_open_utmp failed"); else close(fd); @@ -308,7 +308,7 @@ priv_exec(char *conf, int numeric, int child, int argc, char *argv[]) stat(conf, &cf_info); fd = open(conf, O_RDONLY|O_NONBLOCK, 0); send_fd(sock, fd); - if (fd < 0) + if (fd == -1) warnx("priv_open_config failed"); else close(fd); @@ -316,7 +316,7 @@ priv_exec(char *conf, int numeric, int child, int argc, char *argv[]) case PRIV_CONFIG_MODIFIED: log_debug("[priv]: msg PRIV_CONFIG_MODIFIED received"); - if (stat(conf, &cf_stat) < 0 || + if (stat(conf, &cf_stat) == -1 || timespeccmp(&cf_info.st_mtimespec, &cf_stat.st_mtimespec, <) || cf_info.st_size != cf_stat.st_size) { diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index a398eba5ab5..cd3ce8cc63a 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.259 2019/01/18 15:44:14 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.260 2019/06/28 13:32:51 deraadt Exp $ */ /* * Copyright (c) 2014-2017 Alexander Bluhm @@ -1040,7 +1040,7 @@ klog_readcb(int fd, short event, void *arg) if (n > 0) { linebuf[n] = '\0'; printsys(linebuf); - } else if (n < 0 && errno != EINTR) { + } else if (n == -1 && errno != EINTR) { log_warn("read klog"); event_del(ev); } @@ -1063,7 +1063,7 @@ udp_readcb(int fd, short event, void *arg) cvthname((struct sockaddr *)&sa, resolve, sizeof(resolve)); log_debug("cvthname res: %s", resolve); printline(resolve, linebuf); - } else if (n < 0 && errno != EINTR && errno != EWOULDBLOCK) + } else if (n == -1 && errno != EINTR && errno != EWOULDBLOCK) log_warn("recvfrom udp"); } @@ -1080,7 +1080,7 @@ unix_readcb(int fd, short event, void *arg) if (n > 0) { linebuf[n] = '\0'; printline(LocalHostName, linebuf); - } else if (n < 0 && errno != EINTR && errno != EWOULDBLOCK) + } else if (n == -1 && errno != EINTR && errno != EWOULDBLOCK) log_warn("recvfrom unix"); } @@ -1180,7 +1180,7 @@ acceptcb(int lfd, short event, void *arg, int usetls) } p->p_ctx = NULL; if (usetls) { - if (tls_accept_socket(server_ctx, &p->p_ctx, fd) < 0) { + if (tls_accept_socket(server_ctx, &p->p_ctx, fd) == -1) { log_warnx("tls_accept_socket \"%s\": %s", peername, tls_error(server_ctx)); bufferevent_free(p->p_bufev); @@ -2063,7 +2063,7 @@ fprintlog(struct filed *f, int flags, char *msg) } retryonce = 0; again: - if (writev(f->f_file, iov, 6) < 0) { + if (writev(f->f_file, iov, 6) == -1) { int e = errno; /* allow to recover from file system full */ diff --git a/usr.sbin/syslogd/ttymsg.c b/usr.sbin/syslogd/ttymsg.c index f55e95edfb7..baa6e18ebfd 100644 --- a/usr.sbin/syslogd/ttymsg.c +++ b/usr.sbin/syslogd/ttymsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttymsg.c,v 1.17 2017/10/05 16:15:24 bluhm Exp $ */ +/* $OpenBSD: ttymsg.c,v 1.18 2019/06/28 13:32:51 deraadt Exp $ */ /* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */ /* @@ -112,7 +112,7 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline) * open will fail on slip lines or exclusive-use lines * if not running as root; not an error. */ - if ((fd = priv_open_tty(device)) < 0) { + if ((fd = priv_open_tty(device)) == -1) { if (errno != EBUSY && errno != EACCES) log_warn("priv_open_tty device \"%s\"", device); return; @@ -208,7 +208,7 @@ ttycb(int fd, short event, void *arg) goto done; wret = write(fd, td->td_line, td->td_length); - if (wret < 0 && errno != EINTR && errno != EWOULDBLOCK) + if (wret == -1 && errno != EINTR && errno != EWOULDBLOCK) goto done; if (wret > 0) { td->td_length -= wret; -- cgit v1.2.3-59-g8ed1b