Skip to content

UUID _ifconfig_getnodes() will always return None due to broken logic #98415

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

Closed
csanders-git opened this issue Oct 18, 2022 · 0 comments
Closed
Labels
type-bug An unexpected behavior, bug, or error

Comments

@csanders-git
Copy link
Contributor

csanders-git commented Oct 18, 2022

Bug report

UUID reads the MAC address from the local system in order to generate UUIDv1/v2 spec requests. On Linux and Darwin and unknown platforms it will attempt to run _ifconfig_getnode() to search through ifconfig in order to get the MAC value by searching ifconfig. On MacOS and Unknown platforms it will do this first. (https://github.com/python/cpython/blob/main/Lib/uuid.py#L627)

_ifconfig_getnode() is designed to take a number of args, likely to support multiple systems. Currently this supports 3 flags, '' '-a' and '-av' (https://github.com/python/cpython/blob/main/Lib/uuid.py#L510). This function can never move passed calling the first argument as it will always return. Worse yet, on MacOS and linux passing '' as the argument will actually run the equivalent of /sbin/ifconfig "" which will always return to stderr (which is discarded). This is very likely due to the developer not understanding how popen generates the command string (see https://github.com/python/cpython/blob/main/Lib/subprocess.py#L615)

Due to an incorrectly tabbed return statement this will always result in the function bailing out before testing other valid options. In all tested cases this also results in the function ALWAYS return None. Making the check useless.

    for args in ('', '-a', '-av'):
        mac = _find_mac_near_keyword('ifconfig', args, keywords, lambda i: i+1)
        if mac:
            return mac
        return None

https://github.com/python/cpython/blob/main/Lib/uuid.py#L506

The smallest example of this problem looks something like this

    import subprocess
    """Get the hardware address on Unix by running ifconfig."""
    # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
    for args in ('', '-a', '-av'):
        proc = subprocess.Popen(("/sbin/ifconfig",) + (args,),
                        stdout=subprocess.PIPE,
                        stderr=subprocess.DEVNULL)
        if not proc:
            return None
        stdout, stderr = proc.communicate()
        mac = stdout # This is fine for this example (normally it'd have parsed out a mac
        if mac:
            return mac
        return None

Your environment

  • Python 3.10.6
  • macOS 13.0 Beta 10
@csanders-git csanders-git added the type-bug An unexpected behavior, bug, or error label Oct 18, 2022
@csanders-git csanders-git changed the title UUID _ifconfig_getnodes() will always return None on macOS due to broken logic UUID _ifconfig_getnodes() will always return None due to broken logic Oct 19, 2022
vstinner pushed a commit that referenced this issue Nov 2, 2022
The uuid.getnode() function has multiple implementations, tested sequentially.
The ifconfig implementation was incorrect and always failed: fix it.

In practice, functions of libuuid library are preferred, if available:
uuid_generate_time_safe(), uuid_create() or uuid_generate_time().

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 2, 2022
…98423)

The uuid.getnode() function has multiple implementations, tested sequentially.
The ifconfig implementation was incorrect and always failed: fix it.

In practice, functions of libuuid library are preferred, if available:
uuid_generate_time_safe(), uuid_create() or uuid_generate_time().

(cherry picked from commit e3ec272)

Co-authored-by: Chaim Sanders <csanders-git@users.noreply.github.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 2, 2022
…98423)

The uuid.getnode() function has multiple implementations, tested sequentially.
The ifconfig implementation was incorrect and always failed: fix it.

In practice, functions of libuuid library are preferred, if available:
uuid_generate_time_safe(), uuid_create() or uuid_generate_time().

(cherry picked from commit e3ec272)

Co-authored-by: Chaim Sanders <csanders-git@users.noreply.github.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
miss-islington added a commit that referenced this issue Nov 2, 2022
The uuid.getnode() function has multiple implementations, tested sequentially.
The ifconfig implementation was incorrect and always failed: fix it.

In practice, functions of libuuid library are preferred, if available:
uuid_generate_time_safe(), uuid_create() or uuid_generate_time().

(cherry picked from commit e3ec272)

Co-authored-by: Chaim Sanders <csanders-git@users.noreply.github.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
miss-islington added a commit that referenced this issue Nov 2, 2022
The uuid.getnode() function has multiple implementations, tested sequentially.
The ifconfig implementation was incorrect and always failed: fix it.

In practice, functions of libuuid library are preferred, if available:
uuid_generate_time_safe(), uuid_create() or uuid_generate_time().

(cherry picked from commit e3ec272)

Co-authored-by: Chaim Sanders <csanders-git@users.noreply.github.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
@vstinner vstinner closed this as completed Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy