]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555)
authorGeorge Alexopoulos <giorgosalexo0@gmail.com>
Fri, 15 Nov 2024 10:05:51 +0000 (12:05 +0200)
committerGitHub <noreply@github.com>
Fri, 15 Nov 2024 10:05:51 +0000 (11:05 +0100)
commit8717f792f7cc343599dc60daf80630cceb66145b
tree1b9ed5b2038a75c4bcec76de9568c7268c2c41fe
parentc0f045f7fd3bb7ccf9828f4bfad55347d097fd41
gh-126554: ctypes: Correctly handle NULL dlsym values (GH-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 <grgalex42@gmail.com>
Signed-off-by: Georgios Alexopoulos <grgalex@ba.uoa.gr>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Lib/test/test_ctypes/test_dlerror.py [new file with mode: 0644]
Misc/NEWS.d/next/C_API/2024-11-07-20-24-58.gh-issue-126554.ri12eb.rst [new file with mode: 0644]
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callproc.c