diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-28 00:07:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-28 00:07:19 +0000 |
commit | 7c960f3f657eb9356172290dbf1f678dd3a1c6d1 (patch) | |
tree | 05856047f6b6059561f70d17a0d4719945d53803 /games/larn/main.c | |
parent | 89590a698621620223603b7d825ae162b3af003a (diff) |
Safe $HOME handling.
Diffstat (limited to 'games/larn/main.c')
-rw-r--r-- | games/larn/main.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/games/larn/main.c b/games/larn/main.c index ae8c469bf19..11f07de1fda 100644 --- a/games/larn/main.c +++ b/games/larn/main.c @@ -5,7 +5,9 @@ static char rcsid[] = "$NetBSD: main.c,v 1.7.6.1 1996/05/27 15:54:26 mrg Exp $"; /* main.c */ #include <sys/types.h> #include "header.h" +#include <errno.h> #include <pwd.h> +#include <stdio.h> #include <string.h> static char copyright[]="\nLarn is copyrighted 1986 by Noah Morgan.\n"; @@ -76,9 +78,20 @@ main(argc,argv) strcpy(loginname,ptr); /* save loginname of the user for logging purposes */ strcpy(logname,ptr); /* this will be overwritten with the players name */ if ((ptr = getenv("HOME")) == 0) ptr = "."; - strcpy(savefilename, ptr); - strcat(savefilename, "/Larn.sav"); /* save file name in home directory */ - sprintf(optsfile, "%s/.larnopts",ptr); /* the .larnopts filename */ + if (strlen(ptr) + 9 < sizeof(savefilename)) { + strcpy(savefilename, ptr); + strcat(savefilename, "/Larn.sav"); /* save file name in home directory */ + } else { + fprintf(stderr, "%s/Larn.sav: %s\n", ptr, strerror(ENAMETOOLONG)); + exit(); + } + if (strlen(ptr) + 10 < sizeof(savefilename)) { + strcpy(optsfile, ptr); + strcat(optsfile, "/.larnopts"); /* the .larnopts filename */ + } else { + fprintf(stderr, "%s/.larnopts: %s\n", ptr, strerror(ENAMETOOLONG)); + exit(); + } /* * now malloc the memory for the dungeon |