mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
guestnetworks: 加强ifname内容判断
This commit is contained in:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user