Skip to content

Commit

Permalink
Fix index out of range panic when ifaceName is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Zenghui Shi <[email protected]>
  • Loading branch information
zshi-redhat committed May 7, 2021
1 parent a2e9eaf commit c4c36b7
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 c4c36b7

Please sign in to comment.