diff options
author | Bo Bayles <bbayles@gmail.com> | 2018-01-24 01:11:44 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2018-01-24 01:11:44 (GMT) |
commit | 6b273f7f4056f8276f61a97c789d6bb4425e653c (patch) | |
tree | 755ad323c7f536068884f643c4a882e44ad985ad /Lib/uuid.py | |
parent | 0bad4d63c654d93e1f32ff35026405a3987db5ca (diff) | |
download | cpython-6b273f7f4056f8276f61a97c789d6bb4425e653c.zip cpython-6b273f7f4056f8276f61a97c789d6bb4425e653c.tar.gz cpython-6b273f7f4056f8276f61a97c789d6bb4425e653c.tar.bz2 |
bpo-32502: Discard 64-bit (and other invalid) hardware addresses (#5254)
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r-- | Lib/uuid.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py index b7433cb..ef7b3b5 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -656,7 +656,12 @@ def _random_getnode(): _node = None -def getnode(): +_NODE_GETTERS_WIN32 = [_windll_getnode, _netbios_getnode, _ipconfig_getnode] + +_NODE_GETTERS_UNIX = [_unix_getnode, _ifconfig_getnode, _ip_getnode, + _arp_getnode, _lanscan_getnode, _netstat_getnode] + +def getnode(*, getters=None): """Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could @@ -669,19 +674,18 @@ def getnode(): return _node if sys.platform == 'win32': - getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode] + getters = _NODE_GETTERS_WIN32 else: - getters = [_unix_getnode, _ifconfig_getnode, _ip_getnode, - _arp_getnode, _lanscan_getnode, _netstat_getnode] + getters = _NODE_GETTERS_UNIX for getter in getters + [_random_getnode]: try: _node = getter() except: continue - if _node is not None: + if (_node is not None) and (0 <= _node < (1 << 48)): return _node - assert False, '_random_getnode() returned None' + assert False, '_random_getnode() returned invalid value: {}'.format(_node) _last_timestamp = None |