From d1c9250e343d2ebcb62b6bbc8ceab6b4819d6d62 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 17 May 2016 14:10:30 +0200 Subject: [PATCH] better validation for Ip/Network/Netmask Option --- tiramisu/option/option.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index a36a1c4..06b0b83 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -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