Restricted curses no-prompt file access to current dir or restricted path.
authorDavid Griffith <dave@661.org>
Sun, 7 May 2023 17:59:38 +0000 (10:59 -0700)
committerDavid Griffith <dave@661.org>
Sun, 7 May 2023 17:59:38 +0000 (10:59 -0700)
src/curses/ux_input.c

index b38a6138bec8efafc31ecd66b599b2c11ef5f219..34bd02287ad65c89c030323a1c1c1a0b76afa415 100644 (file)
@@ -1093,8 +1093,17 @@ char *os_read_file_name (const char *default_name, int flag)
        }
 
        /* Use the default name if nothing was typed */
-       if (file_name[0] == 0)
-               strncpy (file_name, default_name, FILENAME_MAX);
+       if (file_name[0] == 0) {
+               /* If FILE_NO_PROMPT, restrict to currect directory. */
+               /* If FILE_NO_PROMPT and using restricted path, then */
+               /*   nothing more needs to be done to restrict the   */
+               /*   file access there. */
+               if (flag == FILE_NO_PROMPT && f_setup.restricted_path == NULL) {
+                       tempname = basename((char *)default_name);
+                       strncpy(file_name, tempname, FILENAME_MAX);
+               } else
+                       strncpy (file_name, default_name, FILENAME_MAX);
+       }
 
        /* If we're restricted to one directory, strip any leading path left
         * over from a previous call to os_read_file_name(), then prepend