Mercurial > hg > early-roguelike
comparison xrogue/state.c @ 310:827441d05b3e
Advanced Rogue family: fix some potential buffer overflows.
Some code for determining the score file location assumed that PATH_MAX
would be less than 1024, which cannot be guaranteed.
Advanced Rogue 5 and 7, and XRogue, have had the buffers for the file
name enlarged. UltraRogue never called the functions, so the code has
been deleted instead.
author | John "Elwin" Edwards |
---|---|
date | Mon, 03 May 2021 19:05:37 -0400 |
parents | 32bc72dcbf4f |
children |
comparison
equal
deleted
inserted
replaced
309:11aeff9acc07 | 310:827441d05b3e |
---|---|
3299 } | 3299 } |
3300 | 3300 |
3301 char * | 3301 char * |
3302 md_getroguedir(void) | 3302 md_getroguedir(void) |
3303 { | 3303 { |
3304 static char path[1024]; | 3304 static char path[PATH_MAX-20]; |
3305 char *end,*home; | 3305 char *end,*home; |
3306 | 3306 |
3307 if ( (home = getenv("ROGUEHOME")) != NULL) | 3307 if ( (home = getenv("ROGUEHOME")) != NULL) |
3308 { | 3308 { |
3309 if (*home) | 3309 if (*home) |
3310 { | 3310 { |
3311 strncpy(path, home, PATH_MAX - 20); | 3311 strncpy(path, home, PATH_MAX - 20); |
3312 | 3312 |
3313 end = &path[strlen(path)-1]; | 3313 if (path[PATH_MAX-21] == '\0') |
3314 | 3314 { |
3315 | 3315 end = &path[strlen(path)-1]; |
3316 while( (end >= path) && ((*end == '/') || (*end == '\\'))) | 3316 |
3317 *end-- = '\0'; | 3317 |
3318 | 3318 while( (end >= path) && ((*end == '/') || (*end == '\\'))) |
3319 if (directory_exists(path)) | 3319 *end-- = '\0'; |
3320 return(path); | 3320 |
3321 if (directory_exists(path)) | |
3322 return(path); | |
3323 } | |
3321 } | 3324 } |
3322 } | 3325 } |
3323 | 3326 |
3324 if (directory_exists("/var/games/roguelike")) | 3327 if (directory_exists("/var/games/roguelike")) |
3325 return("/var/games/roguelike"); | 3328 return("/var/games/roguelike"); |