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 | |
parent | 89590a698621620223603b7d825ae162b3af003a (diff) |
Safe $HOME handling.
-rw-r--r-- | games/larn/header.h | 8 | ||||
-rw-r--r-- | games/larn/main.c | 19 |
2 files changed, 20 insertions, 7 deletions
diff --git a/games/larn/header.h b/games/larn/header.h index e76da385807..ee182683158 100644 --- a/games/larn/header.h +++ b/games/larn/header.h @@ -337,11 +337,11 @@ extern char item[MAXX][MAXY],iven[],know[MAXX][MAXY],larnlevels[],lastmonst[]; extern char level,*levelname[],logfile[],loginname[],logname[],*lpbuf,*lpend; extern char *lpnt,moved[MAXX][MAXY],mitem[MAXX][MAXY],monstlevel[]; extern char monstnamelist[],nch[],ndgg[],nlpts[],nomove,nosignal,nowelcome; -extern char nplt[],nsw[],*objectname[],objnamelist[],optsfile[]; +extern char nplt[],nsw[],*objectname[],objnamelist[],optsfile[1024]; extern char *potionhide[],*potionname[],playerids[],potprob[]; -extern char predostuff,psname[],restorflag,savefilename[],scorefile[],scprob[]; -extern char screen[MAXX][MAXY],*scrollhide[],*scrollname[],sex,*spelcode[]; -extern char *speldescript[]; +extern char predostuff,psname[],restorflag,savefilename[1024],scorefile[]; +extern char scprob[],screen[MAXX][MAXY],*scrollhide[],*scrollname[],sex; +extern char *spelcode[],*speldescript[]; extern char spelknow[],*spelname[],*spelmes[],spelweird[MAXMONST+8][SPNUM]; extern char splev[],stealth[MAXX][MAXY],to_lower[],to_upper[],wizard; extern short diroffx[],diroffy[],hitflag,hit2flag,hit3flag,hitp[MAXX][MAXY]; 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 |