1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

if both stdout and stderr are redirected to a non-tty, pledge(2) will kill

ncurses applications, e.g.:

/usr/games/worms 2>&1 | cat

solve this by only calling pledge(2) after initscr(3) is set and done, or
whatever function that calls it. since pledge(2) is called later now the
promises might be reduced, but this a diff for another day.

found by naddy@ almost a year ago, discussed with him deraadt@ and tb@
ok tb@
This commit is contained in:
mestre 2021-10-23 11:22:48 +00:00
parent 7890901f35
commit bda84ce940
13 changed files with 35 additions and 51 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.30 2016/09/11 14:21:17 tb Exp $ */
/* $OpenBSD: main.c,v 1.31 2021/10/23 11:22:48 mestre Exp $ */
/* $NetBSD: main.c,v 1.4 1995/04/27 21:22:25 mycroft Exp $ */
/*-
@ -64,8 +64,6 @@ main(int argc, char *argv[])
struct sigaction sa;
struct itimerval itv;
if (pledge("stdio rpath wpath cpath flock tty", NULL) == -1)
err(1, "pledge");
open_score_file();
start_time = time(0);
@ -141,6 +139,9 @@ main(int argc, char *argv[])
setup_screen(sp);
if (pledge("stdio rpath wpath cpath flock tty", NULL) == -1)
err(1, "pledge");
addplane();
signal(SIGINT, quit);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.24 2017/07/11 14:32:16 fcambus Exp $ */
/* $OpenBSD: main.c,v 1.25 2021/10/23 11:22:48 mestre Exp $ */
/*
* Copyright (c) 1980, 1993
@ -85,9 +85,6 @@ main (int argc, char **argv)
int i,l; /* non-descript indices */
char c; /* non-descript character storage */
if (pledge("stdio rpath wpath cpath tty exec", NULL) == -1)
err(1, "pledge");
signal(SIGINT, getout); /* trap interrupts */
/* use whole screen for text */
@ -107,6 +104,9 @@ main (int argc, char **argv)
if (cturn == 0)
rflag = 0;
} else {
if (pledge("stdio rpath wpath cpath tty exec", NULL) == -1)
err(1, "pledge");
rscore = wscore = 0; /* zero score */
if (aflag) { /* print rules */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: battlestar.c,v 1.22 2018/02/07 20:22:23 tedu Exp $ */
/* $OpenBSD: battlestar.c,v 1.23 2021/10/23 11:22:48 mestre Exp $ */
/* $NetBSD: battlestar.c,v 1.3 1995/03/21 15:06:47 cgd Exp $ */
/*
@ -50,9 +50,6 @@ main(int argc, char *argv[])
char mainbuf[LINELENGTH];
char *next;
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
open_score_file();
if (argc < 2)
@ -63,6 +60,10 @@ main(int argc, char *argv[])
initialize(argv[1]);
newlocation();
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
for (;;) {
stop_cypher = 0;
next = getcom(mainbuf, sizeof mainbuf, ">-: ",

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bog.c,v 1.33 2016/09/12 20:11:10 tb Exp $ */
/* $OpenBSD: bog.c,v 1.34 2021/10/23 11:22:48 mestre Exp $ */
/* $NetBSD: bog.c,v 1.5 1995/04/24 12:22:32 cgd Exp $ */
/*-
@ -90,9 +90,6 @@ main(int argc, char *argv[])
int ch, done;
char *bspec, *p;
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
batch = debug = reuse = selfuse;
bspec = NULL;
minlength = -1;
@ -164,6 +161,10 @@ main(int argc, char *argv[])
return 0;
}
setup();
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
prompt("Loading the dictionary...");
if ((dictfp = opendict(DICT)) == NULL) {
warn("%s", DICT);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bs.c,v 1.41 2018/08/24 11:14:49 mestre Exp $ */
/* $OpenBSD: bs.c,v 1.42 2021/10/23 11:22:48 mestre Exp $ */
/*
* Copyright (c) 1986, Bruce Holloway
* All rights reserved.
@ -1335,9 +1335,6 @@ scount(int who)
int
main(int argc, char *argv[])
{
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
do_options(argc, argv);
intro();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: crib.c,v 1.23 2016/03/07 12:07:56 mestre Exp $ */
/* $OpenBSD: crib.c,v 1.24 2021/10/23 11:22:48 mestre Exp $ */
/* $NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $ */
/*-
@ -44,9 +44,6 @@ main(int argc, char *argv[])
bool playing;
int ch;
if (pledge("stdio rpath tty proc exec", NULL) == -1)
err(1, "pledge");
while ((ch = getopt(argc, argv, "ehmqr")) != -1)
switch (ch) {
case 'e':

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.32 2016/01/08 21:38:33 mestre Exp $ */
/* $OpenBSD: main.c,v 1.33 2021/10/23 11:22:48 mestre Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@ -80,9 +80,6 @@ main(int argc, char **argv)
};
char *tmpname;
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
if ((tmpname = getlogin()) != NULL)
strlcpy(you, tmpname, sizeof(you));
else
@ -123,6 +120,10 @@ main(int argc, char **argv)
if (interactive)
cursinit(); /* initialize curses */
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
again:
bdinit(board); /* initialize board contents */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: grdc.c,v 1.33 2020/06/06 17:03:16 cheloha Exp $ */
/* $OpenBSD: grdc.c,v 1.34 2021/10/23 11:22:49 mestre Exp $ */
/*
*
* Copyright 2002 Amos Shapir. Public domain.
@ -79,9 +79,6 @@ main(int argc, char *argv[])
int ybase;
int wintoosmall;
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
scrol = wintoosmall = 0;
while ((i = getopt(argc, argv, "sh")) != -1) {
switch (i) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.19 2016/02/28 06:24:06 tb Exp $ */
/* $OpenBSD: main.c,v 1.20 2021/10/23 11:22:49 mestre Exp $ */
/* $NetBSD: main.c,v 1.3 1995/03/23 08:32:50 cgd Exp $ */
/*
@ -49,9 +49,6 @@ main(int argc, char *argv[])
{
int ch;
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
while ((ch = getopt(argc, argv, "d:hk")) != -1) {
switch (ch) {
case 'd':

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mille.c,v 1.25 2016/01/08 18:09:59 mestre Exp $ */
/* $OpenBSD: mille.c,v 1.26 2021/10/23 11:22:49 mestre Exp $ */
/* $NetBSD: mille.c,v 1.4 1995/03/24 05:01:48 cgd Exp $ */
/*
@ -50,9 +50,6 @@ main(int ac, char *av[])
bool restore;
extern char *__progname;
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
#ifdef DEBUG
if (strcmp(av[0], "a.out") == 0) {
outf = fopen("q", "w");
@ -73,6 +70,10 @@ main(int ac, char *av[])
}
Play = PLAYER;
initscr();
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
if ((LINES < 24) || (COLS < 80)) {
endwin();
fprintf(stderr, "Screen must be at least 24x80\n");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rain.c,v 1.21 2016/01/07 16:00:33 tb Exp $ */
/* $OpenBSD: rain.c,v 1.22 2021/10/23 11:22:49 mestre Exp $ */
/*
* Copyright (c) 1980, 1993
@ -59,9 +59,6 @@ main(int argc, char *argv[])
int ch;
int xpos[5], ypos[5];
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
/* set default delay based on terminal baud rate */
if (tcgetattr(STDOUT_FILENO, &term) == 0 &&
(speed = cfgetospeed(&term)) > B9600)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.29 2020/02/14 19:17:33 schwarze Exp $ */
/* $OpenBSD: main.c,v 1.30 2021/10/23 11:22:49 mestre Exp $ */
/* $NetBSD: main.c,v 1.5 1995/04/22 10:08:54 cgd Exp $ */
/*
@ -61,9 +61,6 @@ main(int ac, char *av[])
char *sp;
#endif
if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
err(1, "pledge");
home = getenv("HOME");
if (home == NULL || *home == '\0')
err(1, "getenv");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: worms.c,v 1.29 2018/08/06 06:27:32 mestre Exp $ */
/* $OpenBSD: worms.c,v 1.30 2021/10/23 11:22:49 mestre Exp $ */
/*
* Copyright (c) 1980, 1993
@ -180,9 +180,6 @@ main(int argc, char *argv[])
speed_t speed;
time_t delay = 0;
if (pledge("stdio rpath tty", NULL) == -1)
err(1, "pledge");
/* set default delay based on terminal baud rate */
if (tcgetattr(STDOUT_FILENO, &term) == 0 &&
(speed = cfgetospeed(&term)) > B9600)