ok mvs@

> On 3 Sep 2021, at 19:04, Alexander Bluhm <alexander.bl...@gmx.net> wrote:
> 
> Hi,
> 
> 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?
> 
> bluhm
> 
> Index: usr.sbin/syslogd/syslogd.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.266
> diff -u -p -r1.266 syslogd.c
> --- usr.sbin/syslogd/syslogd.c        14 Jul 2021 13:33:57 -0000      1.266
> +++ usr.sbin/syslogd/syslogd.c        3 Sep 2021 15:56:13 -0000
> @@ -1895,8 +1895,7 @@ logline(int pri, int flags, char *from, 
> 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, ch
>               }
>               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 *i
>               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 *i
>                               break;
>                       if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
>                           UT_NAMESIZE)) {
> -                             ttymsg(iov, 6, utline);
> +                             ttymsg(utline, iov);
>                               break;
>                       }
>               }
> Index: usr.sbin/syslogd/syslogd.h
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.h,v
> retrieving revision 1.33
> diff -u -p -r1.33 syslogd.h
> --- usr.sbin/syslogd/syslogd.h        5 Jul 2019 13:23:27 -0000       1.33
> +++ usr.sbin/syslogd/syslogd.h        3 Sep 2021 15:56:13 -0000
> @@ -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);
> Index: usr.sbin/syslogd/ttymsg.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/ttymsg.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 ttymsg.c
> --- usr.sbin/syslogd/ttymsg.c 28 Jun 2019 13:32:51 -0000      1.18
> +++ usr.sbin/syslogd/ttymsg.c 3 Sep 2021 15:56:13 -0000
> @@ -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".
> 

Reply via email to