Skip to content

gh-46927: Prevent readline from overriding environment #133585

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mbriand
Copy link

@mbriand mbriand commented May 7, 2025

Readline library will set the LINES and COLUMNS environment variables during initialization. One might expect these variables to be updated later on SIGWINCH, but this is not the case with cpython.

As a consequence, when the readline module is imported, any process launched from cpython with the default environment will have LINES and COLUMNS variables set, potentially to a wrong value.

Use the rl_change_environment global variable to disable this initial setup of the environment variables.

@python-cla-bot
Copy link

python-cla-bot bot commented May 7, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented May 7, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

mbriand added 2 commits May 8, 2025 08:55
Readline library will set the LINES and COLUMNS environment variables
during initialization. One might expect these variables to be updated
later on SIGWINCH, but this is not the case with cpython.

As a consequence, when the readline module is imported, any process
launched from cpython with the default environment will have LINES and
COLUMNS variables set, potentially to a wrong value.

Use the rl_change_environment global variable to disable this initial
setup of the environment variables.
@mbriand mbriand force-pushed the fix-issue-46927 branch from 4465cf1 to c2e4e29 Compare May 8, 2025 07:03
@@ -1323,6 +1323,13 @@ setup_readline(readlinestate *mod_state)
/* The name must be defined before initialization */
rl_readline_name = "python";

#if !defined(__APPLE__)
Copy link
Author

Choose a reason for hiding this comment

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

I'm a bit surprised I had to rely on the __APPLE__ define here. As I understand apple OS is using libedit, so I would have thought relying on WITH_EDITLINE would be enough. But the macOS pipeline proved me wrong...

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Please add a test case. The file you're looking for is test_readline.

@mbriand mbriand requested a review from ZeroIntensity May 14, 2025 06:26
@@ -405,6 +407,12 @@ def test_write_read_limited_history(self):
# So, we've only tested that the read did not fail.
# See TestHistoryManipulation for the full test.

@requires_subprocess()
def test_environment_is_not_modified(self):
original_env = dict(os.environ)
Copy link
Member

Choose a reason for hiding this comment

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

Did you forget to add the use of subprocess here? This test always passes.

Copy link
Author

Choose a reason for hiding this comment

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

Err sorry, I reworked the test and forgot to remove the subprocess requirement.

But I do confirm this test fails if I revert the initial commit of the PR.

@mbriand mbriand force-pushed the fix-issue-46927 branch from 6325feb to a91fe5d Compare May 15, 2025 06:18
@mbriand mbriand requested a review from ZeroIntensity May 16, 2025 05:32
@mbriand
Copy link
Author

mbriand commented Jul 10, 2025

Hi!

Any news about this PR? Is there anything I can do to help the this modification being accepted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy