From a592649ae12e5f42c824d607ad223d2847ff4aea Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Tue, 31 Dec 2019 10:00:26 +0800 Subject: [PATCH] =?UTF-8?q?guestnetworks:=20=E5=8A=A0=E5=BC=BAifname?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/guestnetworks.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/compute/models/guestnetworks.go b/pkg/compute/models/guestnetworks.go index d56fb9562f..c18c0ee961 100644 --- a/pkg/compute/models/guestnetworks.go +++ b/pkg/compute/models/guestnetworks.go @@ -257,6 +257,23 @@ func (man *SGuestnetworkManager) ifnameUsed(ifname string) bool { if ifname == "" { return true } + if len(ifname) > MAX_IFNAME_SIZE { + return true + } + isa := func(c byte) bool { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') + } + if !isa(ifname[0]) { + return true + } + for i := range ifname[1:] { + c := ifname[i] + if isa(c) || c >= '0' || c <= '9' || c == '_' || c == '-' { + continue + } + return true + } + count, err := GuestnetworkManager.Query().Equals("ifname", ifname).CountWithError() if err != nil { panic(errors.Wrap(err, "query if ifname is used"))