Change ports range in validators and test function

Current implementation for validating the port number and protocol
number accepts invalid values. For port number it accepts -1 which is
invalid, and the 0 which is used as programming technique for specifying
system-allocated (dynamic) ports. For protocol number it accepts only
one invalid value which is -1.

Proposed solution changes the range of:
- valid port numbers from <-1, 65535> to <1, 65535>
- valid protocol numbers from <-1, 255> to <0, 255>

Co-Authored-By: Wlodzimierz Borkowski <wlodek.borkowski@gmail.com>
Co-Authored-By: Kamil Rykowski <kamil.rykowski@intel.com>

Closes-Bug: 1329571
Closes-Bug: 1431367
Change-Id: I2dc83b611deaa0cc91d586dad1c01d8de91d1957
This commit is contained in:
Wlodzimierz Borkowski
2014-08-24 15:48:18 +02:00
committed by Kamil Rykowski
parent 0fb9a982e7
commit dd9fb91a31
2 changed files with 12 additions and 13 deletions

View File

@@ -14,6 +14,8 @@
import re
from oslo_utils import netutils
from django.core.exceptions import ValidationError # noqa
from django.core import validators # noqa
from django.utils.translation import ugettext_lazy as _
@@ -22,12 +24,12 @@ from horizon import conf
def validate_port_range(port):
if port not in range(-1, 65536):
if not netutils.is_valid_port(port):
raise ValidationError(_("Not a valid port number"))
def validate_ip_protocol(ip_proto):
if ip_proto not in range(-1, 256):
if ip_proto not in range(0, 256):
raise ValidationError(_("Not a valid IP protocol number"))
@@ -45,11 +47,7 @@ def validate_port_or_colon_separated_port_range(port_range):
raise ValidationError(_("One colon allowed in port range"))
ports = port_range.split(':')
for port in ports:
try:
if int(port) not in range(-1, 65536):
raise ValidationError(_("Not a valid port number"))
except ValueError:
raise ValidationError(_("Port number must be integer"))
validate_port_range(port)
# Same as POSIX [:print:]. Accordingly, diacritics are disallowed.
PRINT_REGEX = re.compile(r'^[\x20-\x7E]*$')