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

Proposed by LaMont Jones
Status: Merged
Approved by: LaMont Jones
Approved revision: 5627
Merged at revision: 5627
Proposed branch: lp:~lamont/maas/bug-1655049
Merge into: lp:maas/trunk
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
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+314348@code.launchpad.net

Commit message

Protect get_vendor_for_mac() against IndexError.

Description of the change

Bug#1628761 can also result in IndexError being raised by netaddr.EUI().oui.registration().

To post a comment you must log in.
Mike Pontillo (mpontillo) wrote :

This is unfortunate, but it looks good. Thanks for the fix.

We should probably raise this upstream.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/utils/mac.py'
2--- src/maasserver/utils/mac.py 2016-06-22 17:03:02 +0000
3+++ src/maasserver/utils/mac.py 2017-01-09 17:01:09 +0000
4@@ -18,7 +18,9 @@
5 data = EUI(mac)
6 try:
7 return data.oui.registration().org
8- except (NotRegisteredError, UnicodeDecodeError):
9+ except (IndexError, NotRegisteredError, UnicodeDecodeError):
10+ # Bug#1655049: IndexError is raised for some unicode strings. See also
11+ # Bug#1628761.
12 # UnicodeDecodeError can be raised if the name of the vendor cannot
13 # be decoded from ascii. This is something broken in the netaddr
14 # library, we are just catching the error here not to break the UI.
15
16=== modified file 'src/maasserver/utils/tests/test_mac.py'
17--- src/maasserver/utils/tests/test_mac.py 2016-12-07 12:46:14 +0000
18+++ src/maasserver/utils/tests/test_mac.py 2017-01-09 17:01:09 +0000
19@@ -37,3 +37,16 @@
20 self.assertEqual(
21 "Unknown Vendor",
22 get_vendor_for_mac(factory.make_mac_address()))
23+
24+ def test_get_vendor_survives_index_error(self):
25+ try:
26+ arr = []
27+ arr[3]
28+ except IndexError as exc:
29+ error = exc
30+ eui_result = MagicMock()
31+ eui_result.oui.registration.side_effect = error
32+ self.patch(mac, "EUI").return_value = eui_result
33+ self.assertEqual(
34+ "Unknown Vendor",
35+ get_vendor_for_mac(factory.make_mac_address()))