Check for NULL pointer when stripping extension
authorBill Lash <william.lash@gmail.com>
Tue, 18 Dec 2018 01:52:42 +0000 (19:52 -0600)
committerBill Lash <william.lash@gmail.com>
Tue, 18 Dec 2018 01:52:42 +0000 (19:52 -0600)
When stripping the story file extension, verify that the strrchr()
found the ".".  This ensures that if the file had no extension, ther
will be no SEGFAULT.

src/curses/ux_init.c
src/dumb/dumb_init.c

index 98aa140fdee564cfcf5e567e3dd63b959ac30fb7..72616dc3d814abf4fcaad75a518bc75b7a3ed14c 100644 (file)
@@ -332,7 +332,10 @@ void os_process_arguments (int argc, char *argv[])
 
     /* Now strip off the extension */
     p = strrchr(f_setup.story_name, '.');
-    *p = '\0';  /* extension removed */
+    if ( p != NULL )
+    {
+       *p = '\0';  /* extension removed */
+    }
 
     /* Create nice default file names */
 
index 9b8f74f03455832c06ce7e7ffc7ea93f74cebd71..13b1de952f19a3378d22618b32c6ad2e5810485d 100644 (file)
@@ -146,7 +146,10 @@ void os_process_arguments(int argc, char *argv[])
 
     /* Now strip off the extension */
     p = strrchr(f_setup.story_name, '.');
-    *p = '\0'; /* extension removed */
+    if ( p != NULL )
+    {
+       *p = '\0';      /* extension removed */
+    }
 
     /* Create nice default file names */