From: Holger Schemel Date: Thu, 22 Oct 2015 21:13:03 +0000 (+0200) Subject: fixed horrible bug causing memory access after last argument in 'argv[]' X-Git-Tag: 4.0.0.0-rc1~137 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=2e8b5b6b088bbb3840837fb1ea0acc8af44c54d9;p=rocksndiamonds.git fixed horrible bug causing memory access after last argument in 'argv[]' --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index c1e8eee4..3a7c28f4 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -942,13 +942,18 @@ boolean strSuffixLower(char *s, char *suffix) /* command line option handling functions */ /* ------------------------------------------------------------------------- */ -void GetOptions(char *argv[], +void GetOptions(int argc, char *argv[], void (*print_usage_function)(void), void (*print_version_function)(void)) { char *ro_base_path = RO_BASE_PATH; char *rw_base_path = RW_BASE_PATH; - char **options_left = &argv[1]; + char **argvplus = checked_calloc((argc + 1) * sizeof(char **)); + char **options_left = &argvplus[1]; + + /* replace original "argv" with null-terminated array of string pointers */ + while (argc--) + argvplus[argc] = argv[argc]; /* if the program is configured to start from current directory (default), determine program package directory from program binary (some versions diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 593521ea..8c0e4f43 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -169,7 +169,7 @@ boolean strSuffix(char *, char *); boolean strPrefixLower(char *, char *); boolean strSuffixLower(char *, char *); -void GetOptions(char **, +void GetOptions(int, char **, void (*print_usage_function)(void), void (*print_version_function)(void)); diff --git a/src/main.c b/src/main.c index 3fdc1939..5de7b263 100644 --- a/src/main.c +++ b/src/main.c @@ -5689,7 +5689,7 @@ int main(int argc, char *argv[]) InitExitFunction(CloseAllAndExit); InitPlatformDependentStuff(); - GetOptions(argv, print_usage, print_version); + GetOptions(argc, argv, print_usage, print_version); OpenAll(); EventLoop();