From 3f8aab897970f6bf05eb037c633a82c0f7501798 Mon Sep 17 00:00:00 2001 From: deraadt Date: Sun, 11 Oct 2015 15:27:19 +0000 Subject: [PATCH] pledge "stdio tty" works once the kernel allows TIOCGWINSZ. Do the pledge after TIOCGETD, which the kernel is unlikely to support (does not feel like a good idea for a program to switch line disc, and therefor not worth allowing the program to ask either) --- bin/stty/stty.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/stty/stty.c b/bin/stty/stty.c index c8b6f72d43f..beb80f08d9d 100644 --- a/bin/stty/stty.c +++ b/bin/stty/stty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stty.c,v 1.16 2015/02/15 11:42:30 tedu Exp $ */ +/* $OpenBSD: stty.c,v 1.17 2015/10/11 15:27:19 deraadt Exp $ */ /* $NetBSD: stty.c,v 1.11 1995/03/21 09:11:30 cgd Exp $ */ /*- @@ -80,10 +80,14 @@ main(int argc, char *argv[]) args: argc -= optind; argv += optind; - if (tcgetattr(i.fd, &i.t) < 0) - errx(1, "not a terminal"); if (ioctl(i.fd, TIOCGETD, &i.ldisc) < 0 ) err(1, "TIOCGETD"); + + if (pledge("stdio tty", NULL) == -1) + err(1, "pledge"); + + if (tcgetattr(i.fd, &i.t) < 0) + errx(1, "not a terminal"); if (ioctl(i.fd, TIOCGWINSZ, &i.win) < 0) warn("TIOCGWINSZ"); @@ -94,9 +98,13 @@ args: argc -= optind; /* FALLTHROUGH */ case BSD: case POSIX: + if (pledge("stdio", NULL) == -1) + err(1, "pledge"); print(&i.t, &i.win, i.ldisc, fmt); break; case GFLAG: + if (pledge("stdio", NULL) == -1) + err(1, "pledge"); gprint(&i.t, &i.win, i.ldisc); break; } -- 2.20.1