]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) (#126861)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 17 Nov 2024 17:59:13 +0000 (18:59 +0100)
committerGitHub <noreply@github.com>
Sun, 17 Nov 2024 17:59:13 +0000 (18:59 +0100)
commit52efb95b4527617633c43158c8b73e1c985f28fb
tree53d20d02b6c9f104155a9ba333a436739c52bd45
parentec9cbcb86b211436dd2309e70e367be2454165c3
[3.13] gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) (#126861)

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 8717f792f7cc343599dc60daf80630cceb66145b)

Signed-off-by: Georgios Alexopoulos <grgalex@ba.uoa.gr>
Co-authored-by: George Alexopoulos <giorgosalexo0@gmail.com>
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