+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.
* 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;
/* 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;
{
struct stat rcinfo;
FILE *rcstream;
- char *option, *full_option, *nanorc_save = nanorc;
+ char *option, *nanorc_save = nanorc;
size_t lineno_save = lineno;
option = 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
nanorc = nanorc_save;
lineno = lineno_save;
- cleanup_include:
- free(full_option);
}
/* Return the short value corresponding to the color named in colorname,