From 78825deec761efcae431d89eb06dcf97613e0a95 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 27 Oct 1996 23:51:38 +0000 Subject: Don't make size assumptions wrt $HOME --- games/battlestar/externs.h | 1 + games/battlestar/save.c | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'games/battlestar') 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 #include #include #include 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; -- cgit v1.2.3