-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
ctypes: We do not correctly handle NULL dlsym() return values #126554
Comments
Is it actually a bug? |
EDIT: See Reproducer below. |
I managed to create a reproducer using Indirect Functions (IFUNCS) by adapting this SO answer: https://stackoverflow.com/a/53590014
|
When using
So this turned out to be a bug after all! |
With the interpreter built from my PR we instead get:
|
cc: @efimov-mikhail |
Bug report
Bug description:
The man(3) page for
dlsym()
states:As such, there can be cases where a call to
dlsym
returnsNULL
, while no error has been encountered and the string thatdlerror()
returns has not been (re)set.Currently, (https://github.com/python/cpython/blob/main/Modules/_ctypes/_ctypes.c#L970) we do:
If
dlsym()
returnsNULL
, then by callingdlerror()
we pass eitherNULL
or a previous, unconsumed error string toPyErr_SetString
.In the context of
ctypes
, aNULL
return bydlsym()
might indeed always be considered an error.To correctly express this, we should:
dlerror()
beforedlsym()
, to clear any previous errordlerror()
afterdlsym()
, to see ifdlsym()
encountered any errordlerror()
returns a non-NULL value, then pass its result toPyErr_SetString
dlerror()
returns NULL, then check ifaddress
is NULL, and if so, pass a custom error string toPyErr_SetString
.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: