From 26642a39c307e43f13b27c01a6a981c4b1f17bc7 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 12 May 2019 10:17:36 +0200 Subject: [PATCH] files: allow a given file to be a special file but not a directory 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 d03f4a20..0bdfacf1 100644 --- a/src/files.c +++ b/src/files.c @@ -429,17 +429,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; }