Merge lp:~lamont/maas/bug-1655049-2.1 into lp:maas/2.1

Proposed by LaMont Jones
Status: Merged
Approved by: LaMont Jones
Approved revision: no longer in the source branch.
Merged at revision: 5575
Proposed branch: lp:~lamont/maas/bug-1655049-2.1
Merge into: lp:maas/2.1
Diff against target: 35 lines (+16/-1)
2 files modified
src/maasserver/utils/mac.py (+3/-1)
src/maasserver/utils/tests/test_mac.py (+13/-0)
To merge this branch: bzr merge lp:~lamont/maas/bug-1655049-2.1
Reviewer Review Type Date Requested Status
LaMont Jones (community) Approve
Review via email: mp+314365@code.launchpad.net

Commit message

Backport r5627 from lp:maas: Protect get_vendor_for_mac() against IndexError.

Description of the change

Backport r5627 from lp:maas: Protect get_vendor_for_mac() against IndexError.

To post a comment you must log in.
Revision history for this message
LaMont Jones (lamont) wrote :

Trivial Backport

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/utils/mac.py'
--- src/maasserver/utils/mac.py 2016-06-22 17:03:02 +0000
+++ src/maasserver/utils/mac.py 2017-01-09 19:42:49 +0000
@@ -18,7 +18,9 @@
18 data = EUI(mac)18 data = EUI(mac)
19 try:19 try:
20 return data.oui.registration().org20 return data.oui.registration().org
21 except (NotRegisteredError, UnicodeDecodeError):21 except (IndexError, NotRegisteredError, UnicodeDecodeError):
22 # Bug#1655049: IndexError is raised for some unicode strings. See also
23 # Bug#1628761.
22 # UnicodeDecodeError can be raised if the name of the vendor cannot24 # UnicodeDecodeError can be raised if the name of the vendor cannot
23 # be decoded from ascii. This is something broken in the netaddr25 # be decoded from ascii. This is something broken in the netaddr
24 # library, we are just catching the error here not to break the UI.26 # library, we are just catching the error here not to break the UI.
2527
=== modified file 'src/maasserver/utils/tests/test_mac.py'
--- src/maasserver/utils/tests/test_mac.py 2016-06-22 17:03:02 +0000
+++ src/maasserver/utils/tests/test_mac.py 2017-01-09 19:42:49 +0000
@@ -37,3 +37,16 @@
37 self.assertEqual(37 self.assertEqual(
38 "Unknown Vendor",38 "Unknown Vendor",
39 get_vendor_for_mac(factory.make_mac_address()))39 get_vendor_for_mac(factory.make_mac_address()))
40
41 def test_get_vendor_survives_index_error(self):
42 try:
43 arr = []
44 arr[3]
45 except IndexError as exc:
46 error = exc
47 eui_result = MagicMock()
48 eui_result.oui.registration.side_effect = error
49 self.patch(mac, "EUI").return_value = eui_result
50 self.assertEqual(
51 "Unknown Vendor",
52 get_vendor_for_mac(factory.make_mac_address()))

Subscribers

People subscribed via source and target branches

to all changes: