diff --git a/srogue/main.c b/srogue/main.c index a3d942f..9b7b647 100644 --- a/srogue/main.c +++ b/srogue/main.c @@ -69,7 +69,9 @@ char **envp; scorefile[LINLEN - 1] = '\0'; #else - strcpy(scorefile, homedir); + strncpy(scorefile, homedir, LINLEN-11); + if (scorefile[LINLEN-12] != '\0') + scorefile[0] = '\0'; if (*scorefile) strcat(scorefile,"/"); @@ -444,23 +446,25 @@ directory_exists(char *dirname) char * roguehome() { - static char path[1024]; + static char path[LINLEN+16]; char *end,*home; if ( (home = getenv("ROGUEHOME")) != NULL) { if (*home) { - strncpy(path, home, PATH_MAX - 20); + /* LINLEN - 11 is all that will fit into scorefile */ + strncpy(path, home, LINLEN - 11); + if (path[LINLEN - 12] == '\0') + { + end = &path[strlen(path)-1]; + while( (end >= path) && ((*end == '/') || (*end == '\\'))) + *end-- = '\0'; - end = &path[strlen(path)-1]; - - - while( (end >= path) && ((*end == '/') || (*end == '\\'))) - *end-- = '\0'; - - if (directory_exists(path)) - return(path); + if (directory_exists(path)) + return(path); + } + /* Otherwise home was truncated and should be ignored */ } }