summaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
Diffstat (limited to 'games')
-rw-r--r--games/tetris/scores.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/games/tetris/scores.c b/games/tetris/scores.c
index ebb9b9ba281..7639d2603af 100644
--- a/games/tetris/scores.c
+++ b/games/tetris/scores.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scores.c,v 1.13 2015/11/17 15:27:24 tedu Exp $ */
+/* $OpenBSD: scores.c,v 1.14 2015/11/26 13:24:30 tb Exp $ */
/* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */
/*-
@@ -94,8 +94,8 @@ static char *thisuser(void);
static void
getscores(FILE **fpp)
{
- int sd, mint, mask, i;
- char *mstr, *human;
+ int sd, mint, mask, i, ret;
+ char *mstr, *human, *home;
char scorepath[PATH_MAX];
FILE *sf;
@@ -109,9 +109,15 @@ getscores(FILE **fpp)
mstr = "r";
human = "reading";
}
- if (!getenv("HOME"))
- return;
- snprintf(scorepath, sizeof(scorepath), "%s/%s", getenv("HOME"), ".tetris.scores");
+
+ 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, ".snake.scores");
+
sd = open(scorepath, mint, 0666);
if (sd < 0) {
if (fpp == NULL) {