8000 GH-85724: Ignore the MAC from the Touch Bar interface on macOS in uuid by ronaldoussoren · Pull Request #99717 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-85724: Ignore the MAC from the Touch Bar interface on macOS in uuid #99717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GH-85724: Ignore the MAC from the Touch Bar interface on macOS in uuid
All Intel MacBook Pro devices with a Touch Bar have a network
interface connected to a controller for that device that has
the same MAC address for all MacBooks.

Ignore these MAC adresses in the UUID library.
  • Loading branch information
ronaldoussoren committed Nov 23, 2022
commit 677e9f2542a9a6bdf31c3fa41d6aa1d987bb735a
1 change: 1 addition & 0 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ def check_node(self, node, requires=None):
print(hex, end=' ')
self.assertTrue(0 < node < (1 << 48),
"%s is not an RFC 4122 node ID" % hex)
self.assertNotEqual(node, int("ac:de:48:00:11:22".replace(":", ""), 16))

@unittest.skipUnless(_uuid._ifconfig_getnode in _uuid._GETTERS,
"ifconfig is not used for introspection on this platform")
Expand Down
23 changes: 23 additions & 0 deletions Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,16 @@ 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))

# MAC adresses that are blacklisted for finding a node id
_MAC_BLACKLIST={
# (GH-85724) Hardcoded MAC adres for all Intel MacBook's with Touch Bar.
int("ac:de:48:00:11:22".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.
Expand Down Expand Up @@ -436,6 +443,8 @@ def _find_mac_near_keyword(command, args, keywords, get_word_index):
# real MAC address
pass
else:
if mac in _MAC_BLACKLIST:
continue
if _is_universal(mac):
return mac
first_local_mac = first_local_mac or mac
Expand Down Expand Up @@ -498,6 +507,8 @@ def _find_mac_under_heading(command, args, heading):
mac = _parse_mac(word)
if mac is None:
continue
if mac in _MAC_BLACKLIST:
continue
if _is_universal(mac):
return mac
if first_local_mac is None:
Expand Down Expand Up @@ -581,6 +592,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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure about this test, and in particular not about the test for "darwin".

There are people running Linux on Apple hardware and I don't know if those could be affected by this issue, in particular if there is a driver that exposes a ethernet-like interface to the Touch Bar hardware.

# 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("ac:de:48:00:11:22".replace(":", ""))):
_has_uuid_generate_time_safe = False
_generate_time_safe = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense/be possible to implement this test directly in the _uuid module: remove the function if it returns this address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... Possible yes, sensible maybe not.

The implementation of _uuid.generate_time_safe has 3 or 4 variants (depending on how you count) and because of that an implementation in C mirrors the Python code above but is more verbose and likely not faster than the Python implementation.

I have a patch, but haven't tested it on a device with a Touch Bar yet. That patch adds 49 lines of code to _uuidmodule.c and removes the 4 lines of python code above.

del _x

except ImportError:
_uuid = None
_generate_time_safe = None
Expand Down
0