Skip to content

Commit edbb512

Browse files
committed
gh-101531: Handle omitted leading zeroes in mac address on Darwin (#101531)
1 parent 6e62eb2 commit edbb512

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/uuid.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
if _AIX:
6767
_MAC_DELIM = b'.'
6868
_MAC_OMITS_LEADING_ZEROES = True
69+
if sys.platform in ('darwin', ):
70+
_MAC_OMITS_LEADING_ZEROES = True
6971

7072
RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [
7173
'reserved for NCS compatibility', 'specified in RFC 4122',
@@ -427,7 +429,7 @@ def _find_mac_near_keyword(command, args, keywords, get_word_index):
427429
if words[i] in keywords:
428430
try:
429431
word = words[get_word_index(i)]
430-
mac = int(word.replace(_MAC_DELIM, b''), 16)
432+
mac = _parse_mac(word)
431433
except (ValueError, IndexError):
432434
# Virtual interfaces, such as those provided by
433435
# VPNs, do not have a colon-delimited MAC address
@@ -436,7 +438,7 @@ def _find_mac_near_keyword(command, args, keywords, get_word_index):
436438
# real MAC address
437439
pass
438440
else:
439-
if _is_universal(mac):
441+
if mac and _is_universal(mac):
440442
return mac
441443
first_local_mac = first_local_mac or mac
442444
return first_local_mac or None
@@ -453,10 +455,12 @@ def _parse_mac(word):
453455
if len(parts) != 6:
454456
return
455457
if _MAC_OMITS_LEADING_ZEROES:
456-
# (Only) on AIX the macaddr value given is not prefixed by 0, e.g.
458+
# on AIX and darwin the macaddr value given is not prefixed by 0, e.g. on AIX
457459
# en0 1500 link#2 fa.bc.de.f7.62.4 110854824 0 160133733 0 0
458460
# not
459461
# en0 1500 link#2 fa.bc.de.f7.62.04 110854824 0 160133733 0 0
462+
# and on darwin
463+
# ? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
460464
if not all(1 <= len(part) <= 2 for part in parts):
461465
return
462466
hexstr = b''.join(part.rjust(2, b'0') for part in parts)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle omitted leading zeroes in mac address on Darwin

0 commit comments

Comments
 (0)