From 2823c99e729c031aa2067b0a63e811059e26d037 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Mon, 26 Jan 2009 08:48:22 +0000 Subject: [PATCH] 2009-01-25 Chris Allegretta * 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 --- ChangeLog | 6 ++++++ src/files.c | 15 +++++++++++++-- src/rcfile.c | 19 ++++++------------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86fd49b3..e17e5816 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-01-25 Chris Allegretta + * 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 * 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. diff --git a/src/files.c b/src/files.c index 10c3a798..0f599c9c 100644 --- a/src/files.c +++ b/src/files.c @@ -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; diff --git a/src/rcfile.c b/src/rcfile.c index a12c8014..582015c9 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -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, -- 2.39.5