diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 2003-05-15 02:47:48 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 2003-05-15 02:47:48 +0000 |
commit | 353bdb120265a93d87084704abcff3112a03737e (patch) | |
tree | 07c9c2022cc0da52028bd9976dc4b52e8eb758fa /usr.bin | |
parent | 31c8610b84d2e1be50930b7bff09ec688104b275 (diff) |
Use vis() on any remotely created input before displaying it on a screen.
deraadt@ ok
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mail/cmd1.c | 18 | ||||
-rw-r--r-- | usr.bin/mail/def.h | 5 | ||||
-rw-r--r-- | usr.bin/mail/send.c | 19 |
3 files changed, 28 insertions, 14 deletions
diff --git a/usr.bin/mail/cmd1.c b/usr.bin/mail/cmd1.c index eb7e5daa751..0ca979f2de9 100644 --- a/usr.bin/mail/cmd1.c +++ b/usr.bin/mail/cmd1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd1.c,v 1.22 2001/11/21 20:41:55 millert Exp $ */ +/* $OpenBSD: cmd1.c,v 1.23 2003/05/15 02:47:47 pjanzen Exp $ */ /* $NetBSD: cmd1.c,v 1.9 1997/07/09 05:29:48 mikel Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)cmd1.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: cmd1.c,v 1.22 2001/11/21 20:41:55 millert Exp $"; +static const char rcsid[] = "$OpenBSD: cmd1.c,v 1.23 2003/05/15 02:47:47 pjanzen Exp $"; #endif #endif /* not lint */ @@ -192,6 +192,7 @@ printhead(int mesg) { struct message *mp; char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind; + char visline[LINESIZE]; char pbuf[BUFSIZ]; struct headline hl; int subjlen; @@ -240,14 +241,15 @@ printhead(int mesg) subjline=""; subjlen=0; } + printf("%c%c%3d ", curind, dispc, mesg); + strnvis(visline, name, sizeof(visline), VIS_SAFE|VIS_NOSLASH); if (name == to) - printf("%c%c%3d TO %-14.14s %16.16s %s %.*s\n", - curind, dispc, mesg, name, hl.l_date, wcount, - subjlen, subjline); + printf("TO %-14.14s", visline); else - printf("%c%c%3d %-17.17s %16.16s %s %.*s\n", - curind, dispc, mesg, name, hl.l_date, wcount, - subjlen, subjline); + printf("%-17.17s", visline); + /* hl.l_date was sanity-checked when read in. wcount we just made. */ + strnvis(visline, subjline, sizeof(visline), VIS_SAFE|VIS_NOSLASH); + printf(" %16.16s %s %.*s\n", hl.l_date, wcount, subjlen, visline); } /* diff --git a/usr.bin/mail/def.h b/usr.bin/mail/def.h index 6e2a80c53b9..d48f5ee0f02 100644 --- a/usr.bin/mail/def.h +++ b/usr.bin/mail/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.10 2002/02/16 21:27:48 millert Exp $ */ +/* $OpenBSD: def.h,v 1.11 2003/05/15 02:47:47 pjanzen Exp $ */ /* $NetBSD: def.h,v 1.9 1996/12/28 07:11:00 tls Exp $ */ /* @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)def.h 8.4 (Berkeley) 4/20/95 - * $OpenBSD: def.h,v 1.10 2002/02/16 21:27:48 millert Exp $ + * $OpenBSD: def.h,v 1.11 2003/05/15 02:47:47 pjanzen Exp $ */ /* @@ -58,6 +58,7 @@ #include <string.h> #include <termios.h> #include <unistd.h> +#include <vis.h> #include "pathnames.h" #define APPEND /* New mail goes to end of mailbox */ diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index da7f938159c..204a576cca0 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: send.c,v 1.15 2001/11/28 01:26:35 millert Exp $ */ +/* $OpenBSD: send.c,v 1.16 2003/05/15 02:47:47 pjanzen Exp $ */ /* $NetBSD: send.c,v 1.6 1996/06/08 19:48:39 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)send.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: send.c,v 1.15 2001/11/28 01:26:35 millert Exp $"; +static const char rcsid[] = "$OpenBSD: send.c,v 1.16 2003/05/15 02:47:47 pjanzen Exp $"; #endif #endif /* not lint */ @@ -67,17 +67,20 @@ sendmessage(struct message *mp, FILE *obuf, struct ignoretab *doign, int count; FILE *ibuf; char line[LINESIZE]; + char visline[4 * LINESIZE - 3]; int ishead, infld, ignoring = 0, dostat, firstline; char *cp, *cp2; int c = 0; int length; int prefixlen = 0; int rval; + int dovis; struct sigaction act, saveint; sigset_t oset; sendsignal = 0; rval = -1; + dovis = isatty(fileno(obuf)); sigemptyset(&act.sa_mask); act.sa_flags = SA_RESTART; act.sa_handler = sendint; @@ -199,7 +202,11 @@ sendmessage(struct message *mp, FILE *obuf, struct ignoretab *doign, (void)fwrite(prefix, sizeof(*prefix), prefixlen, obuf); } - (void)fwrite(line, sizeof(*line), length, obuf); + if (dovis) { + length = strvis(visline, line, VIS_SAFE|VIS_NOSLASH); + (void)fwrite(visline, sizeof(*visline), length, obuf); + } else + (void)fwrite(line, sizeof(*line), length, obuf); if (ferror(obuf)) goto out; } @@ -236,7 +243,11 @@ sendmessage(struct message *mp, FILE *obuf, struct ignoretab *doign, */ if (strncmp(line, "From ", 5) == 0) (void)fwrite(">", 1, 1, obuf); /* '>' before 'From ' */ - (void)fwrite(line, sizeof(*line), c, obuf); + if (dovis) { + length = strvis(visline, line, VIS_SAFE|VIS_NOSLASH); + (void)fwrite(visline, sizeof(*visline), length, obuf); + } else + (void)fwrite(line, sizeof(*line), c, obuf); if (ferror(obuf) || sendsignal == SIGINT) goto out; } |