From c4c36b7dcb9b9da844e4096f544f9fe722aac550 Mon Sep 17 00:00:00 2001 From: Zenghui Shi Date: Fri, 7 May 2021 21:22:45 +0800 Subject: [PATCH] Fix index out of range panic when ifaceName is empty Signed-off-by: Zenghui Shi --- pkg/utils/utils.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 199f8fca5..806255493 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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)