commit 26642a39c307e43f13b27c01a6a981c4b1f17bc7
parent 8723375443242cfd4533167ff0db3d3d08021224
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 12 May 2019 10:17:36 +0200
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.
Diffstat:
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git 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;
}