summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormartijn <martijn@openbsd.org>2016-02-05 19:00:39 +0000
committermartijn <martijn@openbsd.org>2016-02-05 19:00:39 +0000
commitf66a1beaf72c5a348d430cdecc52d682108940d0 (patch)
tree51d97a1a60595fa74b4d594d0717f4aaf3ed9702
parentbe more forceful about not using these. (diff)
downloadwireguard-openbsd-f66a1beaf72c5a348d430cdecc52d682108940d0.tar.xz
wireguard-openbsd-f66a1beaf72c5a348d430cdecc52d682108940d0.zip
Make write explicitly ASCII only by transforming UTF-8 characters and non-ASCII
bytes to a single '?'. This prevents sending of potentially harmful bytes to terminals who don't support UTF-8. written with help from schwarze@ text suggestions by jmc@ OK schwarze@ and semarie@
-rw-r--r--usr.bin/write/write.110
-rw-r--r--usr.bin/write/write.c39
2 files changed, 31 insertions, 18 deletions
diff --git a/usr.bin/write/write.1 b/usr.bin/write/write.1
index 3b1a166c13f..65b7b9ee0f9 100644
--- a/usr.bin/write/write.1
+++ b/usr.bin/write/write.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: write.1,v 1.17 2014/06/04 06:07:32 jmc Exp $
+.\" $OpenBSD: write.1,v 1.18 2016/02/05 19:00:39 martijn Exp $
.\"
.\" Copyright (c) 1989, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" from: @(#)write.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: June 4 2014 $
+.Dd $Mdocdate: February 5 2016 $
.Dt WRITE 1
.Os
.Sh NAME
@@ -119,7 +119,11 @@ The
.Nm
utility is compliant with the
.St -p1003.1-2008
-specification.
+specification,
+except that in this implementation
+the sender's locale is ignored.
+Non-ASCII characters are written as
+.Sq \? .
.Sh HISTORY
A
.Nm
diff --git a/usr.bin/write/write.c b/usr.bin/write/write.c
index aae63a63c25..3a45efc9fee 100644
--- a/usr.bin/write/write.c
+++ b/usr.bin/write/write.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: write.c,v 1.32 2015/10/20 20:21:18 bluhm Exp $ */
+/* $OpenBSD: write.c,v 1.33 2016/02/05 19:00:39 martijn Exp $ */
/* $NetBSD: write.c,v 1.5 1995/08/31 21:48:32 jtc Exp $ */
/*
@@ -34,20 +34,20 @@
*/
#include <sys/stat.h>
+
#include <ctype.h>
+#include <err.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <pwd.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <signal.h>
#include <time.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <pwd.h>
#include <unistd.h>
-#include <limits.h>
#include <utmp.h>
-#include <err.h>
-#include <vis.h>
void done(int sig);
void do_write(char *, char *, uid_t);
@@ -55,6 +55,7 @@ void wr_fputs(char *);
void search_utmp(char *, char *, int, char *, uid_t);
int term_chk(char *, int *, time_t *, int);
int utmp_chk(char *, char *);
+static int isu8cont(unsigned char c);
int
main(int argc, char *argv[])
@@ -296,24 +297,32 @@ done(int sig)
void
wr_fputs(char *s)
{
- u_char c;
- char visout[5], *s2;
#define PUTC(c) if (putchar(c) == EOF) goto err;
for (; *s != '\0'; ++s) {
- c = toascii(*s);
- if (c == '\n') {
+ if (*s == '\n') {
PUTC('\r');
PUTC('\n');
continue;
}
- vis(visout, c, VIS_SAFE|VIS_NOSLASH, s[1]);
- for (s2 = visout; *s2; s2++)
- PUTC(*s2);
+ if (isu8cont(*s))
+ continue;
+ if (isprint(*s) || isspace(*s) || *s == '\a') {
+ PUTC(*s);
+ } else {
+ PUTC('?');
+ }
+
}
return;
err: err(1, NULL);
#undef PUTC
}
+
+static int
+isu8cont(unsigned char c)
+{
+ return (c & (0x80 | 0x40)) == 0x80;
+}