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.12] gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) #127764

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Dec 9, 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

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]>
@picnixz
Copy link
Member Author

picnixz commented Dec 9, 2024

I've opened the backport PR so that we are consistent with backporting. But the diff is quite non-trivial since the backport was not automatic. So if you don't want to lose time, we can just say "let's not backport 3.12" (even though you said that you didn't care).

I'm marking the PR as a draft so that we don't merge by mistake.

EDIT 1: Ok I think I messed up the backport.
EDIT 2: I won't be able to check this for the rest of the week.

@picnixz picnixz marked this pull request as ready for review December 15, 2024 13:40
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Thanks, @picnixz.

@serhiy-storchaka serhiy-storchaka merged commit 6ac578c into python:3.12 Dec 17, 2024
32 checks passed
@picnixz picnixz deleted the bp-8717f792f7cc343599dc60daf80630cceb66145b branch December 17, 2024 11:54
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.

3 participants