diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-27 23:51:38 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-27 23:51:38 +0000 |
commit | 78825deec761efcae431d89eb06dcf97613e0a95 (patch) | |
tree | 78fbb2328ec4650e4bb307a09677ecf191ee39ca | |
parent | e4b284d1695c0c1a106c6298b89d87536b29cc27 (diff) |
Don't make size assumptions wrt $HOME
-rw-r--r-- | games/battlestar/externs.h | 1 | ||||
-rw-r--r-- | games/battlestar/save.c | 18 |
2 files changed, 15 insertions, 4 deletions
diff --git a/games/battlestar/externs.h b/games/battlestar/externs.h index ab7f020334d..2a0ef58f3d0 100644 --- a/games/battlestar/externs.h +++ b/games/battlestar/externs.h @@ -35,6 +35,7 @@ * @(#)externs.h 8.1 (Berkeley) 5/31/93 */ +#include <errno.h> #include <signal.h> #include <stdio.h> #include <string.h> diff --git a/games/battlestar/save.c b/games/battlestar/save.c index 85c85951b68..b218d3c01e8 100644 --- a/games/battlestar/save.c +++ b/games/battlestar/save.c @@ -53,8 +53,13 @@ restore() register FILE *fp; home = getenv("HOME"); - strcpy(home1, home); - strcat(home1, "/Bstar"); + if (strlen(home) + 6 < sizeof(home1)) { + strcpy(home1, home); + strcat(home1, "/Bstar"); + } else { + fprintf(stderr, "%s/Bstar: %s\n", home, strerror(ENAMETOOLONG)); + return; + } if ((fp = fopen(home1, "r")) == 0) { perror(home1); return; @@ -106,8 +111,13 @@ save() FILE *fp; home = getenv("HOME"); - strcpy(home1, home); - strcat(home1, "/Bstar"); + if (strlen(home) + 6 < sizeof(home1)) { + strcpy(home1, home); + strcat(home1, "/Bstar"); + } else { + fprintf(stderr, "%s/Bstar: %s\n", home, strerror(ENAMETOOLONG)); + return; + } if ((fp = fopen(home1, "w")) == 0) { perror(home1); return; |