Skip to content
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

bpo-37931: crash on OSX re-initializing os.environ #15428

Merged

Conversation

@benoithudson
Copy link
Contributor

benoithudson commented Aug 23, 2019

On most platforms, the environ symbol is accessible everywhere.

In a dylib on OSX, it's not easily accessible, you need to find it with
_NSGetEnviron.

The code was caching the value of environ. But a setenv can change the value,
leaving garbage at the old value. Fix: don't cache the value of environ, just
read it every time.

https://bugs.python.org/issue37931

On most platforms, the `environ` symbol is accessible everywhere.

In a dylib on OSX, it's not easily accessible, you need to find it with
_NSGetEnviron.

The code was caching the *value* of environ. But a setenv can change the value,
leaving garbage at the old value. Fix: don't cache the value of environ, just
read it every time.
@the-knights-who-say-ni

This comment has been minimized.

Copy link

the-knights-who-say-ni commented Aug 23, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@benoithudson benoithudson changed the title Fix issue 37931: crash on OSX re-initializing os.environ bpo-37931: crash on OSX re-initializing os.environ Aug 23, 2019
@ned-deily ned-deily requested a review from ronaldoussoren Aug 23, 2019
Benoit Hudson
@ned-deily

This comment has been minimized.

Copy link
Member

ned-deily commented Oct 13, 2019

@ronaldoussoren should review this

@ned-deily ned-deily removed their request for review Oct 13, 2019
Copy link
Contributor

ronaldoussoren left a comment

The patch looks good, but its possible to centralise the macOS specific code a bit more, see my comments below.

Modules/posixmodule.c Show resolved Hide resolved
Modules/posixmodule.c Show resolved Hide resolved
Benoit Hudson
@benoithudson

This comment has been minimized.

Copy link
Contributor Author

benoithudson commented Oct 18, 2019

How does backporting work -- do I prepare a new PR for those or does someone else take care of it?

I'd ideally like to backport to 2.7 since that's where I actually hit the bug. This part of the codebase hasn't changed in a long time.

@ned-deily

This comment has been minimized.

Copy link
Member

ned-deily commented Oct 18, 2019

@benoithudson, backporting is attempted automatically when a core developer adds the appropriate "needs backport to ..." labels to the PR, as @ronaldoussoren has done. It could be considered for 2.7.

Copy link
Member

vstinner left a comment

LGTM.

@benoithudson

This comment has been minimized.

Copy link
Contributor Author

benoithudson commented Oct 22, 2019

I can't add labels; if someone can add needs backport to 2.7 that would be great.

Copy link
Contributor

ronaldoussoren left a comment

LGTM

@ronaldoussoren

This comment has been minimized.

Copy link
Contributor

ronaldoussoren commented Oct 22, 2019

That's annoying: "squash and merge" fails for me at the moment, and twice in a row ("Merge attempt failed"). Will try again later.

@benoithudson

This comment has been minimized.

Copy link
Contributor Author

benoithudson commented Nov 4, 2019

Any luck trying again?

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Dec 6, 2019

The change looks perfectly safe to me. I cannot test it, but I trust @benoithudson managed to confirm that his change fix his crash.

@vstinner vstinner merged commit 723f71a into python:master Dec 6, 2019
4 checks passed
4 checks passed
Azure Pipelines PR #20191018.10 succeeded
Details
bedevere/issue-number Issue number 37931 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 6, 2019

Thanks @benoithudson for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.7, 3.8.
🐍🍒🤖

miss-islington added a commit to miss-islington/cpython that referenced this pull request Dec 6, 2019
On most platforms, the `environ` symbol is accessible everywhere.

In a dylib on OSX, it's not easily accessible, you need to find it with
_NSGetEnviron.

The code was caching the *value* of environ. But a setenv() can change the value,
leaving garbage at the old value. Fix: don't cache the value of environ, just
read it every time.
(cherry picked from commit 723f71a)

Co-authored-by: Benoit Hudson <benoit@imgspc.com>
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Dec 6, 2019

GH-17488 is a backport of this pull request to the 3.8 branch.

@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 6, 2019

Sorry, @benoithudson and @vstinner, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 723f71abf7ab0a7be394f9f7b2daa9ecdf6fb1eb 3.7

@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 6, 2019

Sorry @benoithudson and @vstinner, I had trouble checking out the 2.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 723f71abf7ab0a7be394f9f7b2daa9ecdf6fb1eb 2.7

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Dec 6, 2019

@benoithudson: The automated backport to 2.7 and 3.7 failed. Would you mind to attempt to backport manually the change starting with "git cherry-pick -x 723f71a" or use cherry_picker, as explained in previous comments.

@benoithudson

This comment has been minimized.

Copy link
Contributor Author

benoithudson commented Dec 6, 2019

Sure, I'll try to do that this weekend.

miss-islington added a commit that referenced this pull request Dec 6, 2019
On most platforms, the `environ` symbol is accessible everywhere.

In a dylib on OSX, it's not easily accessible, you need to find it with
_NSGetEnviron.

The code was caching the *value* of environ. But a setenv() can change the value,
leaving garbage at the old value. Fix: don't cache the value of environ, just
read it every time.
(cherry picked from commit 723f71a)

Co-authored-by: Benoit Hudson <benoit@imgspc.com>
sthagen added a commit to sthagen/cpython that referenced this pull request Dec 6, 2019
bpo-37931: Fix crash on OSX re-initializing os.environ (pythonGH-15428)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.