GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.12] gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) by picnixz · Pull Request #127764 · python/cpython

Conversation

@picnixz

@picnixz picnixz commented Dec 9, 2024

Copy link
Copy Markdown
Member

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]

  • Issue: ctypes: We do not correctly handle NULL dlsym() return values #126554

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@grgalex @ZeroIntensity
@picnixz @encukou
pythongh-126554: ctypes: Correctly handle NULL dlsym values (pythonGH…
1c543d9
…-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]>
@bedevere-app bedevere-app Bot added the awaiting review label Dec 9, 2024
@picnixz
picnixz requested a review from encukou December 9, 2024 14:16
@bedevere-app bedevere-app Bot mentioned this pull request Dec 9, 2024
ctypes: We do not correctly handle NULL dlsym() return values #126554
Closed
@bedevere-app bedevere-app Bot added the topic-ctypes label Dec 9, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Dec 9, 2024
gh-126554: ctypes: Correctly handle NULL dlsym values #126555
Merged
@picnixz
picnixz marked this pull request as draft December 9, 2024 14:17
@bedevere-app bedevere-app Bot removed the awaiting review label Dec 9, 2024
@picnixz

picnixz commented Dec 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz added 2 commits December 15, 2024 13:52
@picnixz
fix Windows tests
9179fac
@picnixz
Merge branch '3.12' into bp-8717f792f7cc343599dc60daf80630cceb66145b
9fd0eb0
@picnixz
picnixz marked this pull request as ready for review December 15, 2024 13:40
@bedevere-app bedevere-app Bot added the awaiting review label Dec 15, 2024
@picnixz picnixz mentioned this pull request Dec 17, 2024
gh-126742: allow to use non-UTF8 exception messages #126746
Merged
serhiy-storchaka
serhiy-storchaka approved these changes Dec 17, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, @picnixz.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Dec 17, 2024
@serhiy-storchaka
serhiy-storchaka merged commit 6ac578c into python:3.12 Dec 17, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 17, 2024
@picnixz
picnixz deleted the bp-8717f792f7cc343599dc60daf80630cceb66145b branch December 17, 2024 11:54
@petermarko petermarko mentioned this pull request Feb 9, 2025
gh-126554: correct detection of gcc for TestNullDlsym.test_null_dlsym #129872
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@encukou encukou Awaiting requested review from encukou

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-ctypes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@picnixz @serhiy-storchaka @grgalex
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.