fixed horrible bug causing memory access after last argument in 'argv[]'
authorHolger Schemel <info@artsoft.org>
Thu, 22 Oct 2015 21:13:03 +0000 (23:13 +0200)
committerHolger Schemel <info@artsoft.org>
Thu, 22 Oct 2015 21:13:03 +0000 (23:13 +0200)
src/libgame/misc.c
src/libgame/misc.h
src/main.c

index c1e8eee4f9c492a11ba7829282c967a89b09e4b8..3a7c28f4a3b0fe51fcf1d32e755286c119cab217 100644 (file)
@@ -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
index 593521ea323e114a534ad5b2b6ccecb96b0abcb9..8c0e4f431974afc9540cbf2e6d009c9b7ec6ec61 100644 (file)
@@ -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));
 
index 3fdc19391a262be4ea2ac1ab71c4de48c39a0a0e..5de7b263d52437374d3dfe228024eefa16ded56d 100644 (file)
@@ -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();