Skip to content

ctypes.util.find_library() searches the current working directory on macOS #162432

Open

Description

@maurycy

Bug report

On macOS, find_library("ssl") returns /usr/lib/libssl.dylib. However, if the current working directory contains a file named libssl.dylib it'd return it.

The docs say:

uses the system’s standard naming schemes and paths to locate the library, and returns a full pathname if successful:

...and no example shows the current working directory.

On Linux current working directory doesn't have any effect.

And the cwd on macOS comes from yield:

def dyld_default_search(name, env=None):
yield name

I find this behaviour surprising. If an application changes into an untrusted directory and passes the result of find_library("ssl") to ctypes.CDLL(), as in #162362, it loads the local copy.

I think find_library() should stop looking in the working directory. I'm more than happy to provide the PR.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-macstdlibStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions