comparison urogue/mdport.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 e52a8a7ad4c5
children
comparison
equal deleted inserted replaced
309:11aeff9acc07 310:827441d05b3e
399 399
400 return(ret_status); 400 return(ret_status);
401 #endif 401 #endif
402 } 402 }
403 403
404 int
405 directory_exists(char *dirname)
406 {
407 struct stat sb;
408
409 if (stat(dirname, &sb) == 0) /* path exists */
410 return (sb.st_mode & S_IFDIR);
411
412 return(0);
413 }
414
415 char *
416 md_getroguedir()
417 {
418 static char path[1024];
419 char *end,*home;
420
421 if ( (home = getenv("ROGUEHOME")) != NULL)
422 {
423 if (*home)
424 {
425 strncpy(path, home, PATH_MAX - 20);
426
427 end = &path[strlen(path)-1];
428
429 while( (end >= path) && ((*end == '/') || (*end == '\\')))
430 *end-- = '\0';
431
432 if (directory_exists(path))
433 return(path);
434 }
435 }
436
437 if (directory_exists("/var/games/roguelike"))
438 return("/var/games/roguelike");
439 if (directory_exists("/var/lib/roguelike"))
440 return("/var/lib/roguelike");
441 if (directory_exists("/var/roguelike"))
442 return("/var/roguelike");
443 if (directory_exists("/usr/games/lib"))
444 return("/usr/games/lib");
445 if (directory_exists("/games/roguelik"))
446 return("/games/roguelik");
447 if (directory_exists(md_gethomedir()))
448 return(md_gethomedir());
449 return("");
450 }
451
452 char * 404 char *
453 md_getrealname(int uid) 405 md_getrealname(int uid)
454 { 406 {
455 static char uidstr[20]; 407 static char uidstr[20];
456 #if !defined(_WIN32) && !defined(DJGPP) 408 #if !defined(_WIN32) && !defined(DJGPP)