diff options
author | 2016-05-08 16:19:35 +0000 | |
---|---|---|
committer | 2016-05-08 16:19:35 +0000 | |
commit | 99001495fdb0663001064fb2ad910eb33644baf9 (patch) | |
tree | e698ff2d18c4b1fce329c9278438343f5b7050a4 | |
parent | Delete encoding code for the unused TODIGIT information. (diff) | |
download | wireguard-openbsd-99001495fdb0663001064fb2ad910eb33644baf9.tar.xz wireguard-openbsd-99001495fdb0663001064fb2ad910eb33644baf9.zip |
Enable UTF-8 detection in wall(1). This deliberately ignores UTF-8 characters
and replaces them with a single question mark. Similar to write(1).
code OK and tweaks schwarze@
man page adjustment by schwarze@ and OK jmc@
-rw-r--r-- | usr.bin/wall/wall.1 | 15 | ||||
-rw-r--r-- | usr.bin/wall/wall.c | 35 |
2 files changed, 32 insertions, 18 deletions
diff --git a/usr.bin/wall/wall.1 b/usr.bin/wall/wall.1 index b092c2e2077..4d102bc95fe 100644 --- a/usr.bin/wall/wall.1 +++ b/usr.bin/wall/wall.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: wall.1,v 1.11 2007/05/31 19:20:19 jmc Exp $ +.\" $OpenBSD: wall.1,v 1.12 2016/05/08 16:19:35 martijn Exp $ .\" $NetBSD: wall.1,v 1.3 1994/11/17 07:17:57 jtc Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)wall.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: May 8 2016 $ .Dt WALL 1 .Os .Sh NAME @@ -60,6 +60,17 @@ This option may be specified multiple times, and any user in any of the specified groups will receive the message. .El +.Pp +Since the sender's +.Xr locale 1 +need not match the receivers' locales, +.Nm +deliberately ignores the +.Ev LC_CTYPE +environment variable and allows ASCII printable and space characters +only. +Non-printable characters and UTF-8 characters are replaced with +question marks. .Sh SEE ALSO .Xr mesg 1 , .Xr talk 1 , diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c index f972ba90692..b0907fbbe0a 100644 --- a/usr.bin/wall/wall.c +++ b/usr.bin/wall/wall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wall.c,v 1.29 2015/11/05 22:20:11 benno Exp $ */ +/* $OpenBSD: wall.c,v 1.30 2016/05/08 16:19:35 martijn Exp $ */ /* $NetBSD: wall.c,v 1.6 1994/11/17 07:17:58 jtc Exp $ */ /* @@ -40,17 +40,18 @@ #include <sys/time.h> #include <sys/uio.h> +#include <ctype.h> +#include <err.h> +#include <grp.h> +#include <limits.h> #include <paths.h> #include <pwd.h> -#include <grp.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <limits.h> #include <utmp.h> #include <vis.h> -#include <err.h> struct wallgroup { gid_t gid; @@ -68,6 +69,7 @@ void makemsg(char *); void addgroup(struct group *, char *); char *ttymsg(struct iovec *, int, char *, int); __dead void usage(void); +static int isu8cont(unsigned char); int nobanner; int mbufsize; @@ -168,7 +170,7 @@ main(int argc, char **argv) void makemsg(char *fname) { - int ch, cnt; + int cnt; struct tm *lt; struct passwd *pw; struct stat sbuf; @@ -176,8 +178,8 @@ makemsg(char *fname) FILE *fp; int fd; char *p, *whom, hostname[HOST_NAME_MAX+1], lbuf[100], tmpname[PATH_MAX]; - char tmpbuf[5]; char *ttynam; + unsigned char ch; snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXXXXXX", _PATH_TMP); if ((fd = mkstemp(tmpname)) >= 0) { @@ -224,20 +226,15 @@ makemsg(char *fname) } while (fgets(lbuf, sizeof(lbuf), stdin)) for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) { - vis(tmpbuf, ch, VIS_SAFE|VIS_NOSLASH, p[1]); - if (cnt == 79+1-strlen(tmpbuf) || ch == '\n') { - for (; cnt < 79+1-strlen(tmpbuf); ++cnt) + if (cnt == 79 || ch == '\n') { + for (; cnt < 79; ++cnt) putc(' ', fp); putc('\r', fp); putc('\n', fp); cnt = -1; - } - if (ch != '\n') { - int xx; - - for (xx = 0; tmpbuf[xx]; xx++) - putc(tmpbuf[xx], fp); - } + } else if (!isu8cont(ch)) + putc(isprint(ch) || isspace(ch) ? + ch : '?', fp); } (void)fprintf(fp, "%79s\r\n", " "); rewind(fp); @@ -288,3 +285,9 @@ usage(void) (void)fprintf(stderr, "usage: %s [-g group] [file]\n", __progname); exit(1); } + +static int +isu8cont(unsigned char c) +{ + return (c & (0x80 | 0x40)) == 0x80; +} |