From 9a85dda866fca9788e617377732d79b90c65dbda Mon Sep 17 00:00:00 2001 From: Nashwan Azhari Date: Mon, 9 Jan 2023 13:00:15 +0200 Subject: [PATCH] cnitool: add extra checks for the existence of the NETCONFPATH directory. Signed-off-by: Nashwan Azhari --- cnitool/cnitool.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cnitool/cnitool.go b/cnitool/cnitool.go index 0ba91838..b2685bce 100644 --- a/cnitool/cnitool.go +++ b/cnitool/cnitool.go @@ -66,6 +66,23 @@ func main() { if netdir == "" { netdir = DefaultNetDir } + + if !filepath.IsAbs(netdir) { + var err error + netdir, err = filepath.Abs(netdir) + if err != nil { + exit(fmt.Errorf("error converting the provided CNI config path ($%s) %q to an absolute path: %s", EnvNetDir, netdir, err)) + } + } + + if stat, err := os.Stat(netdir); err == nil { + if !stat.IsDir() { + exit(fmt.Errorf("the provided CNI config path ($%s) is not a directory: %q", EnvNetDir, netdir)) + } + } else { + exit(fmt.Errorf("the provided CNI config path ($%s) does not exist: %q", EnvNetDir, netdir)) + } + netconf, err := libcni.LoadConfList(netdir, os.Args[2]) if err != nil { exit(err)