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.
master
parent
8723375443
commit
26642a39c3
11
src/files.c
11
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue