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
This commit is contained in:
David Lawrence Ramsey 2006-04-12 21:44:07 +00:00
parent 4d72de73b1
commit 5fac171c8b
2 changed files with 28 additions and 3 deletions

View File

@ -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:

View File

@ -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)