better validation for Ip/Network/Netmask Option
authorEmmanuel Garette <egarette@cadoles.com>
Tue, 17 May 2016 12:10:30 +0000 (14:10 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Tue, 17 May 2016 12:10:30 +0000 (14:10 +0200)
tiramisu/option/option.py

index a36a1c4..06b0b83 100644 (file)
@@ -192,6 +192,8 @@ class IPOption(Option):
         err = self._impl_valid_unicode(value)
         if err:
             return err
+        if value.count('.') != 3:
+            return ValueError(_('invalid IP'))
         for val in value.split('.'):
             if val.startswith("0") and len(val) > 1:
                 return ValueError(_('invalid IP'))  # pragma: optional cover
@@ -330,6 +332,11 @@ class NetworkOption(Option):
         err = self._impl_valid_unicode(value)
         if err:
             return err
+        if value.count('.') != 3:
+            return ValueError(_('invalid network address'))
+        for val in value.split('.'):
+            if val.startswith("0") and len(val) > 1:
+                return ValueError(_('invalid network address'))
         try:
             IP(value)
         except ValueError:  # pragma: optional cover
@@ -354,6 +361,11 @@ class NetmaskOption(Option):
         err = self._impl_valid_unicode(value)
         if err:
             return err
+        if value.count('.') != 3:
+            return ValueError(_('invalid netmask address'))
+        for val in value.split('.'):
+            if val.startswith("0") and len(val) > 1:
+                return ValueError(_('invalid netmask address'))
         try:
             IP('0.0.0.0/{0}'.format(value))
         except ValueError:  # pragma: optional cover