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: 5576
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.
LaMont Jones (lamont) wrote :

Trivial Backport

review: Approve
lp:~lamont/maas/bug-1655049-2.1 updated
5576. By LaMont Jones on 2017-01-09

Add bug link.

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 19:42:49 +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-06-22 17:03:02 +0000
18+++ src/maasserver/utils/tests/test_mac.py 2017-01-09 19:42:49 +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()))

Subscribers

People subscribed via source and target branches

to all changes: