Title: ctypes: We do not correctly handle NULL dlsym() return values · Issue #126554 · python/cpython · GitHub
Open Graph Title: ctypes: We do not correctly handle NULL dlsym() return values · Issue #126554 · python/cpython
X Title: ctypes: We do not correctly handle NULL dlsym() return values · Issue #126554 · python/cpython
Description: Bug report Bug description: The man(3) page for dlsym() states: In unusual cases (see NOTES) the value of the symbol could actually be NULL. Therefore, a NULL return from dlsym() need not indicate an error. The correct way to distinguish...
Open Graph Description: Bug report Bug description: The man(3) page for dlsym() states: In unusual cases (see NOTES) the value of the symbol could actually be NULL. Therefore, a NULL return from dlsym() need not indicate ...
X Description: Bug report Bug description: The man(3) page for dlsym() states: In unusual cases (see NOTES) the value of the symbol could actually be NULL. Therefore, a NULL return from dlsym() need not indicate ...
Opengraph URL: https://github.com/python/cpython/issues/126554
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ctypes: We do not correctly handle NULL dlsym() return values","articleBody":"# Bug report\n\n### Bug description:\n\nThe man(3) page for `dlsym()` states:\n```\nIn unusual cases (see NOTES) the value of the symbol could actually be\nNULL. Therefore, a NULL return from dlsym() need not indicate an error.\nThe correct way to distinguish an error from a symbol whose value is NULL\nis to call dlerror(3) to clear any old error conditions, then call dl‐\nsym(), and then call dlerror(3) again, saving its return value into a\nvariable, and check whether this saved value is not NULL.\n```\n\nAs such, there can be cases where a call to `dlsym` returns `NULL`, while no error has been encountered and the string that `dlerror()` returns has not been (re)set.\n\nCurrently, (https://github.com/python/cpython/blob/main/Modules/_ctypes/_ctypes.c#L970) we do:\n```C\n\u003c...>\naddress = (void *)dlsym(handle, name);\nif (!address) {\n#ifdef __CYGWIN__\n\u003csnip Windows stuff>\n#else\n PyErr_SetString(PyExc_ValueError, dlerror());\n\u003c...>\n```\n\nIf `dlsym()` returns `NULL`, then by calling `dlerror()` we pass either `NULL` or a previous, unconsumed error string to `PyErr_SetString`.\n\nIn the context of `ctypes`, a `NULL` return by `dlsym()` might indeed always be considered an error.\n\nTo correctly express this, we should:\n- Call `dlerror()` before `dlsym()`, to clear any previous error\n- Call `dlerror()` after `dlsym()`, to see if `dlsym()` encountered any error\n - If `dlerror()` returns a non-NULL value, then pass its result to `PyErr_SetString`\n - If `dlerror()` returns NULL, then check if `address` is NULL, and if so, pass a custom error string to `PyErr_SetString`.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-126555\n* gh-126861\n* gh-127764\n* gh-129872\n* gh-129944\n* gh-129945\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/grgalex","@type":"Person","name":"grgalex"},"datePublished":"2024-11-07T20:17:01Z","url":"https://github.com/python/cpython/issues/126554"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d60166b7-4466-cc6a-69fb-527273d912e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C298:224815:6D5DAB:8F387C:6B026C05 |
| html-safe-nonce | c7a9ba0ddc51f682d021ffce05e64ab89e93c4b3dc9655455ade39632e96a67d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjk4OjIyNDgxNTo2RDVEQUI6OEYzODdDOjZCMDI2QzA1IiwidmlzaXRvcl9pZCI6IjM3NTE1NTI4ODcxNTU3NDc4NDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 37842e76e31e86f10f6aa314cc58736ea707c3e8af9798fdf4f1f5a10a5157e0 |
| hovercard-subject-tag | issue:2642078584 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/126554/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bd2946aa5f37fafebce5fddcea2382afa913e7edd6d307364c29022545b9f205/python/cpython/issues/126554 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bd2946aa5f37fafebce5fddcea2382afa913e7edd6d307364c29022545b9f205/python/cpython/issues/126554 |
| og:image:alt | Bug report Bug description: The man(3) page for dlsym() states: In unusual cases (see NOTES) the value of the symbol could actually be NULL. Therefore, a NULL return from dlsym() need not indicate ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | grgalex |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width