diff options
-rw-r--r-- | games/tetris/scores.c | 11 | ||||
-rw-r--r-- | games/tetris/tetris.c | 25 | ||||
-rw-r--r-- | games/tetris/tetris.h | 5 |
3 files changed, 27 insertions, 14 deletions
diff --git a/games/tetris/scores.c b/games/tetris/scores.c index 471847354f8..a237b4b3cab 100644 --- a/games/tetris/scores.c +++ b/games/tetris/scores.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scores.c,v 1.22 2016/08/27 02:00:10 guenther Exp $ */ +/* $OpenBSD: scores.c,v 1.23 2019/05/18 19:38:25 rob Exp $ */ /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ /*- @@ -93,7 +93,6 @@ getscores(FILE **fpp) { int sd, mint, i, ret; char *mstr, *human, *home; - char scorepath[PATH_MAX]; FILE *sf; if (fpp != NULL) { @@ -107,14 +106,6 @@ getscores(FILE **fpp) human = "reading"; } - home = getenv("HOME"); - if (home == NULL || *home == '\0') - err(1, "getenv"); - - ret = snprintf(scorepath, sizeof(scorepath), "%s/%s", home, ".tetris.scores"); - if (ret < 0 || ret >= PATH_MAX) - errc(1, ENAMETOOLONG, "%s/%s", home, ".tetris.scores"); - sd = open(scorepath, mint, 0666); if (sd < 0) { if (fpp == NULL) { diff --git a/games/tetris/tetris.c b/games/tetris/tetris.c index 9d8149710a4..69f4532a4ac 100644 --- a/games/tetris/tetris.c +++ b/games/tetris/tetris.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tetris.c,v 1.33 2018/04/25 17:41:23 tb Exp $ */ +/* $OpenBSD: tetris.c,v 1.34 2019/05/18 19:38:25 rob Exp $ */ /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ /*- @@ -40,6 +40,7 @@ */ #include <err.h> +#include <errno.h> #include <limits.h> #include <signal.h> #include <stdio.h> @@ -61,6 +62,7 @@ const struct shape *nextshape; long fallrate; int score; char key_msg[100]; +char scorepath[PATH_MAX]; int showpreview, classic; static void elide(void); @@ -150,12 +152,22 @@ main(int argc, char *argv[]) { int pos, c; char *keys; - int level = 2; + int level = 2, ret; char key_write[NUMKEYS][10]; + char *home; const char *errstr; int ch, i, j; - if (pledge("stdio rpath wpath cpath tty", NULL) == -1) + home = getenv("HOME"); + if (home == NULL || *home == '\0') + err(1, "getenv"); + + ret = snprintf(scorepath, sizeof(scorepath), "%s/%s", home, + ".tetris.scores"); + if (ret < 0 || ret >= PATH_MAX) + errc(1, ENAMETOOLONG, "%s/%s", home, ".tetris.scores"); + + if (pledge("stdio rpath wpath cpath tty unveil", NULL) == -1) err(1, "pledge"); keys = "jkl pq"; @@ -220,6 +232,13 @@ main(int argc, char *argv[]) (void)signal(SIGINT, onintr); scr_init(); + + if (unveil(scorepath, "rwc") == -1) + err(1, "unveil"); + + if (pledge("stdio rpath wpath cpath tty", NULL) == -1) + err(1, "pledge"); + setup_board(); scr_set(); diff --git a/games/tetris/tetris.h b/games/tetris/tetris.h index 4faaf365509..0ec176e4b13 100644 --- a/games/tetris/tetris.h +++ b/games/tetris/tetris.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tetris.h,v 1.12 2017/08/13 02:12:16 tedu Exp $ */ +/* $OpenBSD: tetris.h,v 1.13 2019/05/18 19:38:26 rob Exp $ */ /* $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $ */ /*- @@ -35,6 +35,8 @@ * @(#)tetris.h 8.1 (Berkeley) 5/31/93 */ +#include <limits.h> + /* * Definitions for Tetris. */ @@ -169,6 +171,7 @@ extern long fallrate; /* less than 1 billion; smaller => faster */ extern int score; /* the obvious thing */ extern char key_msg[100]; +extern char scorepath[PATH_MAX]; extern int showpreview; extern int classic; |