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
import (
"fmt"
"os"
- "strings"
+ "path/filepath"
"github.com/containernetworking/cni/pkg/types"
)
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 {
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 {