1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Add missing checks for getenv() and snprintf()

From Ricardo Mestre, thanks!
This commit is contained in:
tb 2015-11-26 13:24:30 +00:00
parent abe4198e11
commit 0f70ac25c7

View File

@ -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) {