2009-01-25 Chris Allegretta <chrisa@asty.org>

* files.c (open_file), nanorc.c (parse_include): Don't get_full_path on     
          included rc files, due to it potentially impacting the ability
          to read files in nano's cwd().  Fixes Savnanah bug #25297 reported by Mike 
          Frysinger)



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4353 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2009-01-26 08:48:22 +00:00
parent 019998a877
commit 2823c99e72
3 changed files with 25 additions and 15 deletions

View File

@ -1,3 +1,9 @@
2009-01-25 Chris Allegretta <chrisa@asty.org>
* files.c (open_file), nanorc.c (parse_include): Don't get_full_path on
included rc files, due to it potentially impacting the ability
to read files in nano's cwd(). Fixes Savnanah bug #25297 reported by Mike
Frysinger)
2009-01-24 Chris Allegretta <chrisa@asty.org>
* First pass at some caching of caching color info. Right now it's only for
multi-line regexes but this may not be enough to increase performance.

View File

@ -604,7 +604,7 @@ void read_file(FILE *f, const char *filename, bool undoable)
* return value. *f is set to the opened file. */
int open_file(const char *filename, bool newfie, FILE **f)
{
struct stat fileinfo;
struct stat fileinfo, fileinfo2;
int fd;
char *full_filename;
@ -613,10 +613,21 @@ int open_file(const char *filename, bool newfie, FILE **f)
/* Get the specified file's full path. */
full_filename = get_full_path(filename);
if (full_filename == NULL)
/* Okay, if we can't stat the path due to a component's
permissions, just try the relative one */
if (full_filename == NULL
|| (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
full_filename = mallocstrcpy(NULL, filename);
if (stat(full_filename, &fileinfo) == -1) {
/* Well, maybe we can open the file even if the OS
says its not there */
if ((fd = open(filename, O_RDONLY)) != -1) {
statusbar(_("Reading File"));
free(full_filename);
return 0;
}
if (newfie) {
statusbar(_("New File"));
return -2;

View File

@ -470,7 +470,7 @@ void parse_include(char *ptr)
{
struct stat rcinfo;
FILE *rcstream;
char *option, *full_option, *nanorc_save = nanorc;
char *option, *nanorc_save = nanorc;
size_t lineno_save = lineno;
option = ptr;
@ -478,33 +478,28 @@ void parse_include(char *ptr)
option++;
ptr = parse_argument(ptr);
/* Get the specified file's full path. */
full_option = get_full_path(option);
if (full_option == NULL)
full_option = mallocstrcpy(NULL, option);
/* Can't get the specified file's full path cause it may screw up
our cwd depending on the parent dirs' permissions, (see Savannah bug 25297) */
/* Don't open directories, character files, or block files. */
if (stat(full_option, &rcinfo) != -1) {
if (stat(option, &rcinfo) != -1) {
if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) ||
S_ISBLK(rcinfo.st_mode)) {
rcfile_error(S_ISDIR(rcinfo.st_mode) ?
_("\"%s\" is a directory") :
_("\"%s\" is a device file"), option);
goto cleanup_include;
}
}
/* Open the new syntax file. */
if ((rcstream = fopen(full_option, "rb")) == NULL) {
if ((rcstream = fopen(option, "rb")) == NULL) {
rcfile_error(_("Error reading %s: %s"), option,
strerror(errno));
goto cleanup_include;
}
/* Use the name and line number position of the new syntax file
* while parsing it, so we can know where any errors in it are. */
nanorc = full_option;
nanorc = option;
lineno = 0;
#ifdef DEBUG
@ -522,8 +517,6 @@ void parse_include(char *ptr)
nanorc = nanorc_save;
lineno = lineno_save;
cleanup_include:
free(full_option);
}
/* Return the short value corresponding to the color named in colorname,