From e71c2336be7aa28628e1f8e92f34f9225329220d Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 5 Dec 2024 15:23:52 +0100 Subject: [PATCH] more path validation Signed-off-by: Kristoffer Dalby --- hscontrol/dns/extrarecords.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hscontrol/dns/extrarecords.go b/hscontrol/dns/extrarecords.go index 0c972243ed0..55a393d0807 100644 --- a/hscontrol/dns/extrarecords.go +++ b/hscontrol/dns/extrarecords.go @@ -31,6 +31,15 @@ func NewExtraRecordsMan(path string) (*ExtraRecordsMan, error) { } defer watcher.Close() + fi, err := os.Stat(path) + if err != nil { + return nil, fmt.Errorf("getting file info: %w", err) + } + + if fi.IsDir() { + return nil, fmt.Errorf("path is a directory, only file is supported: %s", path) + } + err = watcher.Add(path) if err != nil { return nil, fmt.Errorf("adding path to watcher: %w", err)