Skip to content

Commit

Permalink
Merge pull request #127 from zshi-redhat/mtu-panic
Browse files Browse the repository at this point in the history
Fix index out of range panic when ifaceName is empty
  • Loading branch information
pliurh authored May 8, 2021
2 parents 433ead3 + c4c36b7 commit 3df178b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ func setNetdevMTU(pciAddr string, mtu int) error {
glog.Warningf("setNetdevMTU(): fail to get interface name for %s: %s", pciAddr, err)
return err
}
if len(ifaceName) < 1 {
return fmt.Errorf("setNetdevMTU(): interface name is empty")
}
mtuFile := "net/" + ifaceName[0] + "/mtu"
mtuFilePath := filepath.Join(sysBusPciDevices, pciAddr, mtuFile)
return ioutil.WriteFile(mtuFilePath, []byte(strconv.Itoa(mtu)), os.ModeAppend)
Expand Down

0 comments on commit 3df178b

Please sign in to comment.