From ec20e3a7a8b4b12caae8622e67c8126053944a06 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 12 Aug 2017 15:52:07 +0200 Subject: [PATCH] tweaks: rename a function, to let it make more sense Further, slightly reword an error message so it is appropriate also when an out-of-bounds file is specified on the command line. --- src/browser.c | 6 +++--- src/files.c | 16 +++++++--------- src/proto.h | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/browser.c b/src/browser.c index 3619365e..2617dbc0 100644 --- a/src/browser.c +++ b/src/browser.c @@ -248,7 +248,7 @@ char *do_browser(char *path) } #ifndef DISABLE_OPERATINGDIR - if (check_operating_dir(path, FALSE)) { + if (outside_of_confinement(path, FALSE)) { /* TRANSLATORS: This refers to the confining effect of the * option --operatingdir, not of --restricted. */ statusline(ALERT, _("Can't go outside of %s"), operating_dir); @@ -281,7 +281,7 @@ char *do_browser(char *path) /* Note: The selected file can be outside the operating * directory if it's ".." or if it's a symlink to a * directory outside the operating directory. */ - if (check_operating_dir(filelist[selected], FALSE)) { + if (outside_of_confinement(filelist[selected], FALSE)) { statusline(ALERT, _("Can't go outside of %s"), operating_dir); continue; } @@ -379,7 +379,7 @@ char *do_browse_from(const char *inpath) #ifndef DISABLE_OPERATINGDIR /* If the resulting path isn't in the operating directory, use * the operating directory instead. */ - if (check_operating_dir(path, FALSE)) + if (outside_of_confinement(path, FALSE)) path = mallocstrcpy(path, operating_dir); #endif diff --git a/src/files.c b/src/files.c index 15beab36..f018e583 100644 --- a/src/files.c +++ b/src/files.c @@ -431,8 +431,8 @@ bool open_buffer(const char *filename, bool undoable) as_an_at = FALSE; #ifndef DISABLE_OPERATINGDIR - if (check_operating_dir(filename, FALSE)) { - statusline(ALERT, _("Can't insert file from outside of %s"), + if (outside_of_confinement(filename, FALSE)) { + statusline(ALERT, _("Can't read file from outside of %s"), operating_dir); return FALSE; } @@ -1424,7 +1424,7 @@ void init_operating_dir(void) * if we are, or TRUE otherwise. If allow_tabcomp is TRUE, allow * incomplete names that would be matches for the operating directory, * so that tab completion will work. */ -bool check_operating_dir(const char *currpath, bool allow_tabcomp) +bool outside_of_confinement(const char *currpath, bool allow_tabcomp) { char *fullpath; bool retval = FALSE; @@ -1583,7 +1583,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, #ifndef DISABLE_OPERATINGDIR /* If we're writing a temporary file, we're probably going outside * the operating directory, so skip the operating directory test. */ - if (!tmp && check_operating_dir(realname, FALSE)) { + if (!tmp && outside_of_confinement(realname, FALSE)) { statusline(ALERT, _("Can't write outside of %s"), operating_dir); goto cleanup_and_exit; } @@ -2437,7 +2437,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches, #ifndef DISABLE_OPERATINGDIR /* ...unless the match exists outside the operating * directory, in which case just go to the next match. */ - if (check_operating_dir(userdata->pw_dir, TRUE)) + if (outside_of_confinement(userdata->pw_dir, TRUE)) continue; #endif @@ -2523,14 +2523,12 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t #ifndef DISABLE_OPERATINGDIR /* ...unless the match exists outside the operating * directory, in which case just go to the next match. */ - if (check_operating_dir(tmp, TRUE)) - skip_match = TRUE; + skip_match = outside_of_confinement(tmp, TRUE); #endif /* ...or unless the match isn't a directory and allow_files * isn't set, in which case just go to the next match. */ - if (!allow_files && !is_dir(tmp)) - skip_match = TRUE; + skip_match = skip_match || (!allow_files && !is_dir(tmp)); free(tmp); diff --git a/src/proto.h b/src/proto.h index b07f0340..4adf84c1 100644 --- a/src/proto.h +++ b/src/proto.h @@ -283,7 +283,7 @@ char *get_full_path(const char *origpath); char *safe_tempfile(FILE **f); #ifndef DISABLE_OPERATINGDIR void init_operating_dir(void); -bool check_operating_dir(const char *currpath, bool allow_tabcomp); +bool outside_of_confinement(const char *currpath, bool allow_tabcomp); #endif #ifndef NANO_TINY void init_backup_dir(void);