commit 5fac171c8b7139d5b6ca41faec20286acb748694
parent 4d72de73b19fbbd841b77f2494481271b73f864f
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 12 Apr 2006 21:44:07 +0000
in 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;
also remove SYSCONFDIR #ifdef, as SYSCONFDIR should always be set
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3369 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -49,6 +49,12 @@ CVS code -
- 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:
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -756,15 +756,24 @@ void parse_rcfile(FILE *rcstream)
* 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
@@ -781,8 +790,18 @@ void do_rcfile(void)
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)