Fix port range check, port should no be greater than 65535.

This commit is contained in:
xiangpengzhao 2016-06-21 04:01:14 -04:00
parent 812b87c8e6
commit 70e3637660
2 changed files with 9 additions and 1 deletions

View File

@ -71,12 +71,17 @@ func (pr *PortRange) Set(value string) error {
high, err = strconv.Atoi(value[hyphenIndex+1:])
}
if err != nil {
return fmt.Errorf("unable to parse port range: %s", value)
return fmt.Errorf("unable to parse port range: %s: %v", value, err)
}
if low > 65535 || high > 65535 {
return fmt.Errorf("the port range cannot be greater than 65535: %s", value)
}
if high < low {
return fmt.Errorf("end port cannot be less than start port: %s", value)
}
pr.Base = low
pr.Size = 1 + high - low
return nil

View File

@ -38,6 +38,9 @@ func TestPortRange(t *testing.T) {
{"100 - 200", false, "", -1, -1},
{"-100", false, "", -1, -1},
{"100-", false, "", -1, -1},
{"200-100", false, "", -1, -1},
{"60000-70000", false, "", -1, -1},
{"70000-80000", false, "", -1, -1},
}
for i := range testCases {