- Simplify the routine for closing the file just before we
indicate success on the statusbar. (DLR)
- rcfile.c:
+ do_rcfile()
+ - Check for the rcfile's being a directory or device file and
+ reject it if it is, for consistency with file handling
+ elsewhere. (DLR)
+ - Remove SYSCONFDIR #ifdef, as SYSCONFDIR should always be set.
+ (DLR)
parse_argument()
- Rename variable ptr_bak to ptr_save, for consistency. (DLR)
- doc/nano.1, doc/nanorc.5, doc/rnano.1, doc/nano.texi:
* followed by the local rcfile. */
void do_rcfile(void)
{
+ struct stat rcinfo;
FILE *rcstream;
-#ifdef SYSCONFDIR
nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
+
+ /* Don't open directories, character files, or block files. */
+ if (stat(nanorc, &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"), nanorc);
+ }
+
/* Try to open the system-wide nanorc. */
rcstream = fopen(nanorc, "rb");
if (rcstream != NULL)
parse_rcfile(rcstream);
-#endif
#if defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
/* We've already read SYSCONFDIR/nanorc, if it's there. If we're
else {
nanorc = charealloc(nanorc, strlen(homedir) + 9);
sprintf(nanorc, "%s/.nanorc", homedir);
- rcstream = fopen(nanorc, "rb");
+ /* Don't open directories, character files, or block files. */
+ if (stat(nanorc, &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"), nanorc);
+ }
+
+ /* Try to open the current user's nanorc. */
+ rcstream = fopen(nanorc, "rb");
if (rcstream == NULL) {
/* Don't complain about the file's not existing. */
if (errno != ENOENT)