--- Coreutils2/coreutils-8.28/src/sort.c 2017-09-01 00:11:03.000000000 -0700 +++ Coreutils/coreutils-8.28/src/sort.c 2018-12-04 17:17:25.960715505 -0800 @@ -108,6 +108,9 @@ struct rlimit { size_t rlim_cur; }; # define DEFAULT_TMPDIR "/tmp" #endif +#define IS_UNSORTABLE_FILE_TYPE(Mode) (S_ISCHR (Mode) \ + || S_ISBLK (Mode) || S_ISFIFO (Mode)) + /* Maximum number of lines to merge every time a NODE is taken from the merge queue. Node is at LEVEL in the binary merge tree, and is responsible for merging TOTAL lines. */ @@ -946,6 +949,7 @@ static FILE * stream_open (char const *file, char const *how) { FILE *fp; + struct stat st; if (*how == 'r') { @@ -956,6 +960,14 @@ stream_open (char const *file, char cons } else { + /* Check for unsupported file types */ + stat (file, &st); + if (IS_UNSORTABLE_FILE_TYPE (st.st_mode)) + { + die (SORT_FAILURE, errno, _("cannot sort special file %s"), + quoteaf (file)); + } + int fd = open (file, O_RDONLY | O_CLOEXEC); fp = fd < 0 ? NULL : fdopen (fd, how); }