spec, libcni, pkg/invoke: Use OS-agnostic separator when parsing CNI_PATH
authorOnur <onur.filiz@microsoft.com>
Sat, 28 Jan 2017 21:30:00 +0000 (13:30 -0800)
committerOnur Filiz <onur.filiz@microsoft.com>
Sun, 29 Jan 2017 00:47:58 +0000 (16:47 -0800)
Hardcoding the list separator character as ":" causes CNI to fail when parsing
CNI_PATH on other operating systems. For example, Windows uses ";" as list
separator because ":" can legally appear in paths such as "C:\path\to\file".
This change replaces use of ":" with OS-agnostic APIs or os.PathListSeparator.

Fixes #358

invoke/delegate.go

index f25bedd..c78a69e 100644 (file)
@@ -17,7 +17,7 @@ package invoke
 import (
        "fmt"
        "os"
-       "strings"
+       "path/filepath"
 
        "github.com/containernetworking/cni/pkg/types"
 )
@@ -27,7 +27,7 @@ func DelegateAdd(delegatePlugin string, netconf []byte) (types.Result, error) {
                return nil, fmt.Errorf("CNI_COMMAND is not ADD")
        }
 
-       paths := strings.Split(os.Getenv("CNI_PATH"), ":")
+       paths := filepath.SplitList(os.Getenv("CNI_PATH"))
 
        pluginPath, err := FindInPath(delegatePlugin, paths)
        if err != nil {
@@ -42,7 +42,7 @@ func DelegateDel(delegatePlugin string, netconf []byte) error {
                return fmt.Errorf("CNI_COMMAND is not DEL")
        }
 
-       paths := strings.Split(os.Getenv("CNI_PATH"), ":")
+       paths := filepath.SplitList(os.Getenv("CNI_PATH"))
 
        pluginPath, err := FindInPath(delegatePlugin, paths)
        if err != nil {