diff options
author | tb <tb@cvs.openbsd.org> | 2015-11-26 13:24:31 +0000 |
---|---|---|
committer | tb <tb@cvs.openbsd.org> | 2015-11-26 13:24:31 +0000 |
commit | 611d14d18580f33cb0a620fcffd691a6f0d74fe8 (patch) | |
tree | 65f01a8b01a6dc5161f5dce885c05abd63ffc32c /games | |
parent | c3dc851d8ae43999d94fdba0b79a1bb4369b1c89 (diff) |
Add missing checks for getenv() and snprintf()
From Ricardo Mestre, thanks!
Diffstat (limited to 'games')
-rw-r--r-- | games/tetris/scores.c | 18 |
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) { |