diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2021-09-03 16:28:34 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2021-09-03 16:28:34 +0000 |
commit | 562bd13c16f2bafe89c42489d0ec06b2b02c5e32 (patch) | |
tree | 35163ddfae7f72105b66b310ed7d8fc0cdd3090e /usr.sbin/syslogd | |
parent | 21daa0970af02fcbcdecb3ab30f5bf19d9988f6c (diff) |
Use a define for the iov array size in syslogd. This is better
than passing the magic number 6 around and checking at runtime
whether its fits.
OK deraadt@ martijn@ mvs@
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 11 | ||||
-rw-r--r-- | usr.sbin/syslogd/syslogd.h | 6 | ||||
-rw-r--r-- | usr.sbin/syslogd/ttymsg.c | 16 |
3 files changed, 13 insertions, 20 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index a7c1e505c6c..8632f29bc25 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.266 2021/07/14 13:33:57 kn Exp $ */ +/* $OpenBSD: syslogd.c,v 1.267 2021/09/03 16:28:33 bluhm Exp $ */ /* * Copyright (c) 2014-2017 Alexander Bluhm <bluhm@genua.de> @@ -1895,8 +1895,7 @@ logline(int pri, int flags, char *from, char *msg) void fprintlog(struct filed *f, int flags, char *msg) { - struct iovec iov[6]; - struct iovec *v; + struct iovec iov[IOVCNT], *v; int l, retryonce; char line[LOG_MAXLINE + 1], repbuf[80], greetings[500]; char ebuf[ERRBUFSIZE]; @@ -2072,7 +2071,7 @@ fprintlog(struct filed *f, int flags, char *msg) } retryonce = 0; again: - if (writev(f->f_file, iov, 6) == -1) { + if (writev(f->f_file, iov, IOVCNT) == -1) { int e = errno; /* allow to recover from file system full */ @@ -2201,7 +2200,7 @@ wallmsg(struct filed *f, struct iovec *iov) strncpy(utline, ut.ut_line, sizeof(utline) - 1); utline[sizeof(utline) - 1] = '\0'; if (f->f_type == F_WALL) { - ttymsg(iov, 6, utline); + ttymsg(utline, iov); continue; } /* should we send the message to this user? */ @@ -2210,7 +2209,7 @@ wallmsg(struct filed *f, struct iovec *iov) break; if (!strncmp(f->f_un.f_uname[i], ut.ut_name, UT_NAMESIZE)) { - ttymsg(iov, 6, utline); + ttymsg(utline, iov); break; } } diff --git a/usr.sbin/syslogd/syslogd.h b/usr.sbin/syslogd/syslogd.h index ff3efcf5985..55c53ea313f 100644 --- a/usr.sbin/syslogd/syslogd.h +++ b/usr.sbin/syslogd/syslogd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.h,v 1.33 2019/07/05 13:23:27 bluhm Exp $ */ +/* $OpenBSD: syslogd.h,v 1.34 2021/09/03 16:28:33 bluhm Exp $ */ /* * Copyright (c) 2014-2017 Alexander Bluhm <bluhm@genua.de> @@ -35,10 +35,12 @@ int priv_config_modified(void); int priv_getaddrinfo(char *, char *, char *, struct sockaddr *, size_t); int priv_getnameinfo(struct sockaddr *, socklen_t, char *, size_t); +#define IOVCNT 6 + /* Terminal message */ #define TTYMSGTIME 1 /* timeout used by ttymsg */ #define TTYMAXDELAY 256 /* max events in ttymsg */ -void ttymsg(struct iovec *, int, char *); +void ttymsg(char *, struct iovec *); /* File descriptor send/recv */ void send_fd(int, int); diff --git a/usr.sbin/syslogd/ttymsg.c b/usr.sbin/syslogd/ttymsg.c index baa6e18ebfd..42fa1c1093c 100644 --- a/usr.sbin/syslogd/ttymsg.c +++ b/usr.sbin/syslogd/ttymsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttymsg.c,v 1.18 2019/06/28 13:32:51 deraadt Exp $ */ +/* $OpenBSD: ttymsg.c,v 1.19 2021/09/03 16:28:33 bluhm Exp $ */ /* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */ /* @@ -62,10 +62,6 @@ #include "log.h" #include "syslogd.h" -#ifndef nitems -#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) -#endif - struct tty_delay { struct event td_event; size_t td_length; @@ -80,18 +76,14 @@ void ttycb(int, short, void *); * seconds. */ void -ttymsg(struct iovec *iov, int iovcnt, char *utline) +ttymsg(char *utline, struct iovec *iov) { static char device[MAXNAMLEN] = _PATH_DEV; + struct iovec localiov[IOVCNT]; + int iovcnt = IOVCNT; int cnt, fd; size_t left; ssize_t wret; - struct iovec localiov[6]; - - if (iovcnt < 0 || (size_t)iovcnt > nitems(localiov)) { - log_warnx("too many iov's (change code in syslogd/ttymsg.c)"); - return; - } /* * Ignore lines that start with "ftp" or "uucp". |