Hello Dan Kenigsberg,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/26367

to review the following change.

Change subject: Do not allow empty network names (bridged nor bridgeless)
......................................................................

Do not allow empty network names (bridged nor bridgeless)

It was possible to create empty network names that ended up in
libvirt networks called 'vdsm-'. This patch solved it returning
the appropriate error and not allowing empty bridge names in the
internal representation either.

Change-Id: I1d1e5d9fb284eb67936daf197e3025314a29f58b
Bug-Url: https://bugzilla.redhat.com/1078899
Signed-off-by: Antoni S. Puimedon <[email protected]>
Reviewed-on: http://gerrit.ovirt.org/26263
Reviewed-by: Dan Kenigsberg <[email protected]>
---
M tests/netmodelsTests.py
M vdsm/configNetwork.py
M vdsm/netmodels.py
3 files changed, 6 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/67/26367/1

diff --git a/tests/netmodelsTests.py b/tests/netmodelsTests.py
index 6181a9e..7dc5df2 100644
--- a/tests/netmodelsTests.py
+++ b/tests/netmodelsTests.py
@@ -53,7 +53,7 @@
         self.assertEqual(Vlan.validateTag(Vlan.MAX_ID), None)
 
     def testIsBridgeNameValid(self):
-        invalidBrName = ('-abc', 'abcdefghijklmnop', 'a:b', 'a.b')
+        invalidBrName = ('', '-abc', 'abcdefghijklmnop', 'a:b', 'a.b')
         for i in invalidBrName:
             with self.assertRaises(neterrors.ConfigNetworkError) \
                     as cneContext:
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 78b5012..2b3ebe6 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -121,7 +121,7 @@
             topNetDev = Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
     if vlan is not None:
         topNetDev = Vlan(topNetDev, vlan, configurator, mtu=mtu)
-    if bridge:
+    if bridge is not None:
         topNetDev = Bridge(bridge, configurator, port=topNetDev, mtu=mtu,
                            stp=opts.get('stp'))
     if topNetDev is None:
@@ -235,6 +235,9 @@
     if mtu:
         mtu = int(mtu)
 
+    if network == '':
+        raise ConfigNetworkError(ne.ERR_BAD_BRIDGE,
+                                 'Empty network names are not valid')
     if prefix:
         if netmask:
             raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
diff --git a/vdsm/netmodels.py b/vdsm/netmodels.py
index 5fde4e0..f718670 100644
--- a/vdsm/netmodels.py
+++ b/vdsm/netmodels.py
@@ -164,7 +164,7 @@
 
     @classmethod
     def validateName(cls, name):
-        if not (name and len(name) <= cls.MAX_NAME_LEN and
+        if not (name and 0 < len(name) <= cls.MAX_NAME_LEN and
                 len(set(name) & cls.ILLEGAL_CHARS) == 0 and
                 not name.startswith('-')):
             raise ConfigNetworkError(ne.ERR_BAD_BRIDGE,


-- 
To view, visit http://gerrit.ovirt.org/26367
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d1e5d9fb284eb67936daf197e3025314a29f58b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.4
Gerrit-Owner: Antoni Segura Puimedon <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to