diff options
| author | jtc <jtc@NetBSD.org> | 1994-11-17 07:17:53 +0000 |
|---|---|---|
| committer | jtc <jtc@NetBSD.org> | 1994-11-17 07:17:53 +0000 |
| commit | a8bfd3d17acdf360bcfa394c375f8a39cfc31df4 (patch) | |
| tree | da03bac165230f686406885f0250ba51ef800d18 /lib/libutil | |
| parent | c0b8fbbaad4dd65cbd830a8205052bbe1269a151 (diff) | |
Merged with 4.4lite
Changed to conform to NetBSD's new RCS Id conventions.
Diffstat (limited to 'lib/libutil')
| -rw-r--r-- | lib/libutil/ttymsg.c | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/libutil/ttymsg.c b/lib/libutil/ttymsg.c index 19911a47c45..982481fe4e7 100644 --- a/lib/libutil/ttymsg.c +++ b/lib/libutil/ttymsg.c @@ -1,6 +1,8 @@ +/* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */ + /* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,8 +34,10 @@ */ #ifndef lint -/*static char sccsid[] = "from: @(#)ttymsg.c 5.8 (Berkeley) 7/1/91";*/ -static char rcsid[] = "$Id: ttymsg.c,v 1.2 1993/08/01 18:03:09 mycroft Exp $"; +#if 0 +static char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93"; +#endif +static char rcsid[] = "$NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -49,17 +53,18 @@ static char rcsid[] = "$Id: ttymsg.c,v 1.2 1993/08/01 18:03:09 mycroft Exp $"; #include <stdlib.h> /* - * Display the contents of a uio structure on a terminal. Used by wall(1) - * and syslogd(8). Forks and finishes in child if write would block, waiting - * at most five minutes. Returns pointer to error string on unexpected error; - * string is not newline-terminated. Various "normal" errors are ignored - * (exclusive-use, lack of permission, etc.). + * Display the contents of a uio structure on a terminal. Used by wall(1), + * syslogd(8), and talkd(8). Forks and finishes in child if write would block, + * waiting up to tmout seconds. Returns pointer to error string on unexpected + * error; string is not newline-terminated. Various "normal" errors are + * ignored (exclusive-use, lack of permission, etc.). */ char * -ttymsg(iov, iovcnt, line) +ttymsg(iov, iovcnt, line, tmout) struct iovec *iov; int iovcnt; char *line; + int tmout; { static char device[MAXNAMLEN] = _PATH_DEV; static char errbuf[1024]; @@ -67,13 +72,21 @@ ttymsg(iov, iovcnt, line) struct iovec localiov[6]; int forked = 0; - if (iovcnt > 6) + if (iovcnt > sizeof(localiov) / sizeof(localiov[0])) return ("too many iov's (change code in wall/ttymsg.c)"); + + (void) strcpy(device + sizeof(_PATH_DEV) - 1, line); + if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) { + /* A slash is an attempt to break security... */ + (void) snprintf(errbuf, sizeof(errbuf), "'/' in \"%s\"", + device); + return (errbuf); + } + /* * open will fail on slip lines or exclusive-use lines * if not running as root; not an error. */ - (void) strcpy(device + sizeof(_PATH_DEV) - 1, line); if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) { if (errno == EBUSY || errno == EACCES) return (NULL); @@ -92,7 +105,7 @@ ttymsg(iov, iovcnt, line) if (wret >= 0) { left -= wret; if (iov != localiov) { - bcopy(iov, localiov, + bcopy(iov, localiov, iovcnt * sizeof(struct iovec)); iov = localiov; } @@ -126,14 +139,14 @@ ttymsg(iov, iovcnt, line) return (NULL); } forked++; - /* wait at most 5 minutes */ + /* wait at most tmout seconds */ (void) signal(SIGALRM, SIG_DFL); (void) signal(SIGTERM, SIG_DFL); /* XXX */ (void) sigsetmask(0); - (void) alarm((u_int)(60 * 5)); + (void) alarm((u_int)tmout); (void) fcntl(fd, O_NONBLOCK, &off); continue; - } + } /* * We get ENODEV on a slip line if we're running as root, * and EIO if the line just went away. |
