nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH 1/2] files: allow a given file to be a special file


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 1/2] files: allow a given file to be a special file but not a directory
Date: Sun, 12 May 2019 10:57:13 +0200

The original requests (https://bugs.debian.org/551717 by Paul Wise,
and https://savannah.gnu.org/bugs/?45383 by Mike Frysinger) asked
only that specifying a directory instead of a file name should not
open a new buffer.  But commit 98ffb642 excluded everything that was
not a normal file.  This avoids a hang when the user accidentally
tries to open a pipe or a socket, but also prevents any user from
doing so on purpose.  And opening a fifo can be useful when wanting
to handle sensitive data that shouldn't be stored on disk.

This prepares the fix for https://bugs.debian.org/583196.
---
 src/files.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/files.c b/src/files.c
index b9d894f3..8646cd81 100644
--- a/src/files.c
+++ b/src/files.c
@@ -436,17 +436,12 @@ bool open_buffer(const char *filename, bool new_buffer)
 
        realname = real_dir_from_tilde(filename);
 
-       /* When the specified filename is not empty, and the corresponding
-        * file exists, verify that it is a normal file. */
+       /* When the given filename refers to a directory, don't try to open it. 
*/
        if (*filename != '\0') {
                struct stat fileinfo;
 
-               if (stat(realname, &fileinfo) == 0 && 
!(S_ISREG(fileinfo.st_mode) ||
-                                       (ISSET(NOREAD_MODE) && 
S_ISFIFO(fileinfo.st_mode)))) {
-                       if (S_ISDIR(fileinfo.st_mode))
-                               statusline(ALERT, _("\"%s\" is a directory"), 
realname);
-                       else
-                               statusline(ALERT, _("\"%s\" is not a normal 
file"), realname);
+               if (stat(realname, &fileinfo) == 0 && 
S_ISDIR(fileinfo.st_mode)) {
+                       statusline(ALERT, _("\"%s\" is a directory"), realname);
                        free(realname);
                        return FALSE;
                }
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]