files: when the requested operating directory cannot be set, fail
Specifying an operating directory should either lead to a successfull confinement, or nano should fail to start. (Also: save the terminal settings as soon as possible, so that an early die() will not restore uninitialized values.) This fixes the first part of https://savannah.gnu.org/bugs/?47798 properly.master
parent
5aa1df37d1
commit
aa09abe198
12
src/files.c
12
src/files.c
|
@ -1563,15 +1563,9 @@ void init_operating_dir(void)
|
||||||
|
|
||||||
full_operating_dir = get_full_path(operating_dir);
|
full_operating_dir = get_full_path(operating_dir);
|
||||||
|
|
||||||
/* If get_full_path() failed or the operating directory is
|
/* If the operating directory is inaccessible, fail. */
|
||||||
* inaccessible, unset operating_dir. */
|
if (full_operating_dir == NULL || chdir(full_operating_dir) == -1)
|
||||||
if (full_operating_dir == NULL || chdir(full_operating_dir) == -1) {
|
die("Invalid operating directory\n");
|
||||||
statusline(ALERT, _("Not a valid directory: %s"), operating_dir);
|
|
||||||
free(full_operating_dir);
|
|
||||||
full_operating_dir = NULL;
|
|
||||||
free(operating_dir);
|
|
||||||
operating_dir = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if we're inside the operating directory. Return FALSE
|
/* Check to see if we're inside the operating directory. Return FALSE
|
||||||
|
|
18
src/nano.c
18
src/nano.c
|
@ -2037,6 +2037,9 @@ int main(int argc, char **argv)
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Back up the terminal settings so that they can be restored. */
|
||||||
|
tcgetattr(0, &oldterm);
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
{
|
{
|
||||||
/* If the locale set exists and uses UTF-8, we should use
|
/* If the locale set exists and uses UTF-8, we should use
|
||||||
|
@ -2423,6 +2426,12 @@ int main(int argc, char **argv)
|
||||||
init_backup_dir();
|
init_backup_dir();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DISABLE_OPERATINGDIR
|
||||||
|
/* Set up the operating directory. This entails chdir()ing there,
|
||||||
|
* so that file reads and writes will be based there. */
|
||||||
|
init_operating_dir();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_JUSTIFY
|
#ifndef DISABLE_JUSTIFY
|
||||||
/* If punct wasn't specified, set its default value. */
|
/* If punct wasn't specified, set its default value. */
|
||||||
if (punct == NULL)
|
if (punct == NULL)
|
||||||
|
@ -2504,9 +2513,6 @@ int main(int argc, char **argv)
|
||||||
if (tabsize == -1)
|
if (tabsize == -1)
|
||||||
tabsize = WIDTH_OF_TAB;
|
tabsize = WIDTH_OF_TAB;
|
||||||
|
|
||||||
/* Back up the old terminal settings so that they can be restored. */
|
|
||||||
tcgetattr(0, &oldterm);
|
|
||||||
|
|
||||||
/* Initialize curses mode. If this fails, get out. */
|
/* Initialize curses mode. If this fails, get out. */
|
||||||
if (initscr() == NULL)
|
if (initscr() == NULL)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -2554,12 +2560,6 @@ int main(int argc, char **argv)
|
||||||
controlright = key_defined(keyvalue);
|
controlright = key_defined(keyvalue);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_OPERATINGDIR
|
|
||||||
/* Set up the operating directory. This entails chdir()ing there,
|
|
||||||
* so that file reads and writes will be based there. */
|
|
||||||
init_operating_dir();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Main: open file\n");
|
fprintf(stderr, "Main: open file\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue