guestnetworks: 加强ifname内容判断

This commit is contained in:
Yousong Zhou
2019-12-31 10:10:55 +08:00
parent 90e36bcc76
commit a592649ae1
+17
View File
@@ -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"))