From 4eb99890f86991a66799146ea7011ce0ce532565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Fri, 6 Nov 2020 09:48:35 +0100 Subject: [PATCH] Check if Filebeat log harvester tries to open named pipe (#20450) (#22422) ## What does this PR do? This PR adds a check before opening a file for harvester Filebeat. If the file is a named pipe, an error is returned and the file is not opened. ## Why is it important? Previously if someone wanted to open a named pipe without a writer, Filebeat hangs. ## Related issues Closes #18682 (cherry picked from commit a89d81f27582e4236633b990727ca98ee4e6c80b) --- filebeat/input/log/harvester.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/filebeat/input/log/harvester.go b/filebeat/input/log/harvester.go index f40dc8639167..6b16861f8ece 100644 --- a/filebeat/input/log/harvester.go +++ b/filebeat/input/log/harvester.go @@ -515,6 +515,14 @@ func (h *Harvester) shouldExportLine(line string) bool { // is returned and the harvester is closed. The file will be picked up again the next time // the file system is scanned func (h *Harvester) openFile() error { + fi, err := os.Stat(h.state.Source) + if err != nil { + return fmt.Errorf("failed to stat source file %s: %v", h.state.Source, err) + } + if fi.Mode()&os.ModeNamedPipe != 0 { + return fmt.Errorf("failed to open file %s, named pipes are not supported", h.state.Source) + } + f, err := file_helper.ReadOpen(h.state.Source) if err != nil { return fmt.Errorf("Failed opening %s: %s", h.state.Source, err)