Skip to content
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

[3.13] gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) #126861

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 15, 2024

For dlsym(), a return value of NULL does not necessarily indicate
an error 1.

Therefore, to avoid using stale (or NULL) dlerror() values, we must:

  1. clear the previous error state by calling dlerror()
  2. call dlsym()
  3. call dlerror()

If the return value of dlerror() is not NULL, an error occured.

In ctypes we choose to treat a NULL return value from dlsym()
as a "not found" error. This is the same as the fallback
message we use on Windows, Cygwin or when getting/formatting
the error reason fails.

(cherry picked from commit 8717f79)

Co-authored-by: George Alexopoulos [email protected]
Signed-off-by: Georgios Alexopoulos [email protected]
Signed-off-by: Georgios Alexopoulos [email protected]
Co-authored-by: Peter Bierma [email protected]
Co-authored-by: Bénédikt Tran [email protected]
Co-authored-by: Petr Viktorin [email protected]

…-126555)

For dlsym(), a return value of NULL does not necessarily indicate
an error [1].

Therefore, to avoid using stale (or NULL) dlerror() values, we must:

 1. clear the previous error state by calling dlerror()
 2. call dlsym()
 3. call dlerror()

If the return value of dlerror() is not NULL, an error occured.

In ctypes we choose to treat a NULL return value from dlsym()
as a "not found" error. This is the same as the fallback
message we use on Windows, Cygwin or when getting/formatting
the error reason fails.

[1]: https://man7.org/linux/man-pages/man3/dlsym.3.html

(cherry picked from commit 8717f79)

Co-authored-by: George Alexopoulos <[email protected]>
Signed-off-by: Georgios Alexopoulos <[email protected]>
Signed-off-by: Georgios Alexopoulos <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @encukou for commit 5b4116e 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 15, 2024
@ambv ambv merged commit 52efb95 into python:3.13 Nov 17, 2024
111 of 113 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants