diff --git a/cmd/ndm_daemonset/probe/usedbyprobe.go b/cmd/ndm_daemonset/probe/usedbyprobe.go index d32af9ca6..844691060 100644 --- a/cmd/ndm_daemonset/probe/usedbyprobe.go +++ b/cmd/ndm_daemonset/probe/usedbyprobe.go @@ -19,6 +19,7 @@ package probe import ( "errors" "os" + "path/filepath" "strings" "syscall" @@ -200,7 +201,7 @@ func getBlockDeviceZFSPartition(bd blockdevice.BlockDevice) (string, bool) { // isBlockDeviceInUseByKernel tries to open the device exclusively to check if the device is // being held by some process. eg: If kernel zfs uses the disk, the open will fail func isBlockDeviceInUseByKernel(path string) (bool, error) { - f, err := os.OpenFile(path, os.O_EXCL, 0444) + f, err := os.OpenFile(filepath.Clean(path), os.O_EXCL, 0444) if errors.Is(err, syscall.EBUSY) { return true, nil diff --git a/integration_tests/utils/file.go b/integration_tests/utils/file.go index ae99140ff..974cefce5 100644 --- a/integration_tests/utils/file.go +++ b/integration_tests/utils/file.go @@ -20,11 +20,12 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" ) // GetYAMLString gets the yaml-string from the given YAML file func GetYAMLString(fileName string) (string, error) { - fileBytes, err := ioutil.ReadFile(fileName) + fileBytes, err := ioutil.ReadFile(filepath.Clean(fileName)) if err != nil { return "", err } diff --git a/pkg/sysfs/util.go b/pkg/sysfs/util.go index 71d600464..3115ddccb 100644 --- a/pkg/sysfs/util.go +++ b/pkg/sysfs/util.go @@ -18,6 +18,7 @@ package sysfs import ( "io/ioutil" + "path/filepath" "strconv" "strings" ) @@ -25,7 +26,7 @@ import ( // readSysFSFileAsInt64 reads a file and // converts that content into int64 func readSysFSFileAsInt64(sysFilePath string) (int64, error) { - b, err := ioutil.ReadFile(sysFilePath) + b, err := ioutil.ReadFile(filepath.Clean(sysFilePath)) if err != nil { return 0, err } @@ -33,7 +34,7 @@ func readSysFSFileAsInt64(sysFilePath string) (int64, error) { } func readSysFSFileAsString(sysFilePath string) (string, error) { - b, err := ioutil.ReadFile(sysFilePath) + b, err := ioutil.ReadFile(filepath.Clean(sysFilePath)) if err != nil { return "", err } diff --git a/pkg/udev/mockdata.go b/pkg/udev/mockdata.go index a1dffdab0..6aaea762d 100644 --- a/pkg/udev/mockdata.go +++ b/pkg/udev/mockdata.go @@ -25,12 +25,14 @@ package udev import "C" import ( "bufio" - bd "github.com/openebs/node-disk-manager/blockdevice" - "github.com/openebs/node-disk-manager/pkg/mount" - "github.com/openebs/node-disk-manager/pkg/sysfs" "io/ioutil" "os" + "path/filepath" "strings" + + bd "github.com/openebs/node-disk-manager/blockdevice" + "github.com/openebs/node-disk-manager/pkg/mount" + "github.com/openebs/node-disk-manager/pkg/sysfs" ) // MockOsDiskDetails struct contain different attribute of os disk. @@ -140,7 +142,7 @@ func OsDiskName() (string, string, error) { // getSyspathOfOsDisk returns syspath of os disk in success func getSyspathOfOsDisk(osDiskName string) (string, error) { - data, err := ioutil.ReadFile("/sys/class/block/" + osDiskName + "/dev") + data, err := ioutil.ReadFile(filepath.Clean("/sys/class/block/" + osDiskName + "/dev")) if err != nil { return "", err } @@ -149,7 +151,7 @@ func getSyspathOfOsDisk(osDiskName string) (string, error) { // getOsDiskSize returns size of os disk in success func getOsDiskSize(osDiskName string) (string, error) { - sizeByte, err := ioutil.ReadFile("/sys/class/block/" + osDiskName + "/size") + sizeByte, err := ioutil.ReadFile(filepath.Clean("/sys/class/block/" + osDiskName + "/size")) if err != nil { return "", err }