diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 411eec0f406215..80fd5f213a6448 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -805,10 +805,13 @@ def test_find_mac_near_keyword(self): data = ''' fake Link encap:UNSPEC hwaddr 00-00 cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 +en5 Link encap:UNSPEC HWaddr ac:de:48:00:11:22 eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab ''' # The above data will only be parsed properly on non-AIX unixes. + # The value for 'en5' is the single MAC address used by Touch Bar Mac laptops + # and should be ignored. with mock.patch.multiple(self.uuid, _MAC_DELIM=b':', _MAC_OMITS_LEADING_ZEROES=False, @@ -831,6 +834,10 @@ def check_node(self, node, requires=None): self.assertTrue(0 < node < (1 << 48), "%s is not an RFC 4122 node ID" % hex) + # GH-85724: Ensure that the MAC address of the TouchBar interface + # on Intel Macbooks is not used in a UUID. + self.assertNotEqual(node, self.uuid._MACOS_TOUCHBAR_MAC_AS_INT) + @unittest.skipUnless(_uuid._ifconfig_getnode in _uuid._GETTERS, "ifconfig is not used for introspection on this platform") def test_ifconfig_getnode(self): diff --git a/Lib/uuid.py b/Lib/uuid.py index e863b631877f6d..ca207b36a4d6a4 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -403,9 +403,13 @@ def _get_command_stdout(command, *args): # # See https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local + def _is_universal(mac): return not (mac & (1 << 41)) +# (GH-85724) Hardcoded MAC address for all Intel MacBook's with Touch Bar. +_MACOS_TOUCHBAR_MAC="ac:de:48:00:11:22" +_MACOS_TOUCHBAR_MAC_AS_INT=int(_MACOS_TOUCHBAR_MAC.replace(":", ""), 16) def _find_mac_near_keyword(command, args, keywords, get_word_index): """Searches a command's output for a MAC address near a keyword. @@ -436,6 +440,8 @@ def _find_mac_near_keyword(command, args, keywords, get_word_index): # real MAC address pass else: + if mac == _MACOS_TOUCHBAR_MAC_AS_INT: + continue if _is_universal(mac): return mac first_local_mac = first_local_mac or mac @@ -498,6 +504,8 @@ def _find_mac_under_heading(command, args, heading): mac = _parse_mac(word) if mac is None: continue + if mac == _MACOS_TOUCHBAR_MAC_AS_INT: + continue if _is_universal(mac): return mac if first_local_mac is None: @@ -581,6 +589,18 @@ def _netbios_getnode(): _generate_time_safe = getattr(_uuid, "generate_time_safe", None) _UuidCreate = getattr(_uuid, "UuidCreate", None) _has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe + + if sys.platform == "darwin" and _generate_time_safe is not None: + # On macOS check if generate_time_safe uses the MAC adddress + # of the Touch Bar on Intel Macbooks and ignore the function + # if it does because this is a single MAC adress for all + # devices. See GH-85724 + _x = _generate_time_safe()[0] + if _x.endswith(bytes.fromhex(_MACOS_TOUCHBAR_MAC.replace(":", ""))): + _has_uuid_generate_time_safe = False + _generate_time_safe = None + del _x + except ImportError: _uuid = None _generate_time_safe = None