From: Benno Schulenberg Date: Fri, 17 Jul 2015 20:40:44 +0000 (+0000) Subject: Verifying that a named and existing file is a normal file, to avoid X-Git-Tag: v2.5.0~158 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=98ffb642f376f77243a8ab921d6cdee0cbb0d349;p=nano.git Verifying that a named and existing file is a normal file, to avoid opening an empty buffer when the name of a directory is specified. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5304 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index e5acf355..61fb69ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-07-17 Benno Schulenberg + * src/files.c (open_buffer): Verify that a named and existing file + is a normal file, to avoid opening an empty buffer when the name of + a directory is specified. This fixes Savannah bug #45383 reported + by Mike Frysinger, and also Savannah bug #27839 (which is an echo + from Debian bug #551717 reported by Paul Wise). + 2015-07-17 Mike Frysinger * src/browser.c (browser_refresh): Use the proper type (off_t) for the size of a file, and avoid warnings about too large bit shifts. diff --git a/src/files.c b/src/files.c index 2198fac2..4c491fd1 100644 --- a/src/files.c +++ b/src/files.c @@ -339,6 +339,21 @@ void open_buffer(const char *filename, bool undoable) } #endif + /* When the specified filename is not empty, and the thing exists, + * verify that it is a normal file. */ + if (strcmp(filename, "") != 0) { + struct stat fileinfo; + + if (stat(filename, &fileinfo) == 0 && !S_ISREG(fileinfo.st_mode)) { + if (S_ISDIR(fileinfo.st_mode)) + statusbar(_("\"%s\" is a directory"), filename); + else + statusbar(_("\"%s\" is not a normal file"), filename); + beep(); + return; + } + } + /* If we're going to load into a new buffer, first create the new * buffer and lock the corresponding file. */ if (new_buffer) {