tweaks: elide the global variable 'full_operating_dir'
There is no need to retain the (relative) path that the user specified, so we can simply reuse that variable.master
parent
751e7f0fbe
commit
dd88842d5a
|
@ -251,8 +251,7 @@ char *do_browser(char *path)
|
||||||
if (check_operating_dir(path, FALSE)) {
|
if (check_operating_dir(path, FALSE)) {
|
||||||
/* TRANSLATORS: This refers to the confining effect of the
|
/* TRANSLATORS: This refers to the confining effect of the
|
||||||
* option --operatingdir, not of --restricted. */
|
* option --operatingdir, not of --restricted. */
|
||||||
statusline(ALERT, _("Can't go outside of %s"),
|
statusline(ALERT, _("Can't go outside of %s"), operating_dir);
|
||||||
full_operating_dir);
|
|
||||||
path = mallocstrcpy(path, present_path);
|
path = mallocstrcpy(path, present_path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -283,8 +282,7 @@ char *do_browser(char *path)
|
||||||
* directory if it's ".." or if it's a symlink to a
|
* directory if it's ".." or if it's a symlink to a
|
||||||
* directory outside the operating directory. */
|
* directory outside the operating directory. */
|
||||||
if (check_operating_dir(filelist[selected], FALSE)) {
|
if (check_operating_dir(filelist[selected], FALSE)) {
|
||||||
statusline(ALERT, _("Can't go outside of %s"),
|
statusline(ALERT, _("Can't go outside of %s"), operating_dir);
|
||||||
full_operating_dir);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
21
src/files.c
21
src/files.c
|
@ -433,7 +433,7 @@ bool open_buffer(const char *filename, bool undoable)
|
||||||
#ifndef DISABLE_OPERATINGDIR
|
#ifndef DISABLE_OPERATINGDIR
|
||||||
if (check_operating_dir(filename, FALSE)) {
|
if (check_operating_dir(filename, FALSE)) {
|
||||||
statusline(ALERT, _("Can't insert file from outside of %s"),
|
statusline(ALERT, _("Can't insert file from outside of %s"),
|
||||||
full_operating_dir);
|
operating_dir);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1411,13 +1411,13 @@ char *safe_tempfile(FILE **f)
|
||||||
/* Change to the specified operating directory, when it's valid. */
|
/* Change to the specified operating directory, when it's valid. */
|
||||||
void init_operating_dir(void)
|
void init_operating_dir(void)
|
||||||
{
|
{
|
||||||
full_operating_dir = get_full_path(operating_dir);
|
operating_dir = free_and_assign(operating_dir, get_full_path(operating_dir));
|
||||||
|
|
||||||
/* If the operating directory is inaccessible, fail. */
|
/* If the operating directory is inaccessible, fail. */
|
||||||
if (full_operating_dir == NULL || chdir(full_operating_dir) == -1)
|
if (operating_dir == NULL || chdir(operating_dir) == -1)
|
||||||
die(_("Invalid operating directory\n"));
|
die(_("Invalid operating directory\n"));
|
||||||
|
|
||||||
snuggly_fit(&full_operating_dir);
|
snuggly_fit(&operating_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if we're inside the operating directory. Return FALSE
|
/* Check to see if we're inside the operating directory. Return FALSE
|
||||||
|
@ -1426,11 +1426,6 @@ void init_operating_dir(void)
|
||||||
* so that tab completion will work. */
|
* so that tab completion will work. */
|
||||||
bool check_operating_dir(const char *currpath, bool allow_tabcomp)
|
bool check_operating_dir(const char *currpath, bool allow_tabcomp)
|
||||||
{
|
{
|
||||||
/* full_operating_dir is global for memory cleanup. It should have
|
|
||||||
* already been initialized by init_operating_dir(). Also, a
|
|
||||||
* relative operating directory path will only be handled properly
|
|
||||||
* if this is done. */
|
|
||||||
|
|
||||||
char *fullpath;
|
char *fullpath;
|
||||||
bool retval = FALSE;
|
bool retval = FALSE;
|
||||||
const char *whereami1, *whereami2 = NULL;
|
const char *whereami1, *whereami2 = NULL;
|
||||||
|
@ -1451,16 +1446,16 @@ bool check_operating_dir(const char *currpath, bool allow_tabcomp)
|
||||||
if (fullpath == NULL)
|
if (fullpath == NULL)
|
||||||
return allow_tabcomp;
|
return allow_tabcomp;
|
||||||
|
|
||||||
whereami1 = strstr(fullpath, full_operating_dir);
|
whereami1 = strstr(fullpath, operating_dir);
|
||||||
if (allow_tabcomp)
|
if (allow_tabcomp)
|
||||||
whereami2 = strstr(full_operating_dir, fullpath);
|
whereami2 = strstr(operating_dir, fullpath);
|
||||||
|
|
||||||
/* If both searches failed, we're outside the operating directory.
|
/* If both searches failed, we're outside the operating directory.
|
||||||
* Otherwise, check the search results. If the full operating
|
* Otherwise, check the search results. If the full operating
|
||||||
* directory path is not at the beginning of the full current path
|
* directory path is not at the beginning of the full current path
|
||||||
* (for normal usage) and vice versa (for tab completion, if we're
|
* (for normal usage) and vice versa (for tab completion, if we're
|
||||||
* allowing it), we're outside the operating directory. */
|
* allowing it), we're outside the operating directory. */
|
||||||
if (whereami1 != fullpath && whereami2 != full_operating_dir)
|
if (whereami1 != fullpath && whereami2 != operating_dir)
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
|
|
||||||
|
@ -1589,7 +1584,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
|
||||||
/* If we're writing a temporary file, we're probably going outside
|
/* If we're writing a temporary file, we're probably going outside
|
||||||
* the operating directory, so skip the operating directory test. */
|
* the operating directory, so skip the operating directory test. */
|
||||||
if (!tmp && check_operating_dir(realname, FALSE)) {
|
if (!tmp && check_operating_dir(realname, FALSE)) {
|
||||||
statusline(ALERT, _("Can't write outside of %s"), full_operating_dir);
|
statusline(ALERT, _("Can't write outside of %s"), operating_dir);
|
||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -165,10 +165,7 @@ const char *locking_suffix = ".swp";
|
||||||
#endif
|
#endif
|
||||||
#ifndef DISABLE_OPERATINGDIR
|
#ifndef DISABLE_OPERATINGDIR
|
||||||
char *operating_dir = NULL;
|
char *operating_dir = NULL;
|
||||||
/* The relative path to the operating directory, which we can't
|
/* The path to our confining "operating" directory, when given. */
|
||||||
* move outside of. */
|
|
||||||
char *full_operating_dir = NULL;
|
|
||||||
/* The full path to it. */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_SPELLER
|
#ifndef DISABLE_SPELLER
|
||||||
|
@ -1735,7 +1732,6 @@ void thanks_for_all_the_fish(void)
|
||||||
#endif
|
#endif
|
||||||
#ifndef DISABLE_OPERATINGDIR
|
#ifndef DISABLE_OPERATINGDIR
|
||||||
free(operating_dir);
|
free(operating_dir);
|
||||||
free(full_operating_dir);
|
|
||||||
#endif
|
#endif
|
||||||
free(answer);
|
free(answer);
|
||||||
free(last_search);
|
free(last_search);
|
||||||
|
|
|
@ -132,7 +132,6 @@ extern const char *locking_suffix;
|
||||||
#endif
|
#endif
|
||||||
#ifndef DISABLE_OPERATINGDIR
|
#ifndef DISABLE_OPERATINGDIR
|
||||||
extern char *operating_dir;
|
extern char *operating_dir;
|
||||||
extern char *full_operating_dir;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_SPELLER
|
#ifndef DISABLE_SPELLER
|
||||||
|
|
Loading…
Reference in New Issue