Skip to content

[2.7] bpo-29854: Fix segfault in call_readline()#2637

Merged
berkerpeksag merged 1 commit into
python:2.7from
nirs:bpo-29854-2.7
Jul 10, 2017
Merged

[2.7] bpo-29854: Fix segfault in call_readline()#2637
berkerpeksag merged 1 commit into
python:2.7from
nirs:bpo-29854-2.7

Conversation

@nirs
Copy link
Copy Markdown
Contributor

@nirs nirs commented Jul 8, 2017

Tested on Fedora 25, FreeBSD 10.3, FreeBSD 11.0.

On OS X 10.11.6, python 2.7 builds without readline since configure fail to find rl_resize_terminal in -lreadline, so I could not test it.

@berkerpeksag, @Haypo please review.

(cherry picked from commit fae8f4a)

If history-length is set in .inputrc, and the history file is double the
history size (or more), history_get(N) returns NULL, and python
segfaults. Fix that by checking for NULL return value.

It seems that the root cause is incorrect handling of bigger history in
readline, but Python should not segfault even if readline returns
unexpected value.

This issue affects only GNU readline. When using libedit emulation
system history size option does not work.

This is a backport of the actual fix from master without the test, since
the test depends on new run_pty() helper which is not available in 2.7.
@berkerpeksag
Copy link
Copy Markdown
Member

On OS X 10.11.6, python 2.7 builds without readline since configure fail to find rl_resize_terminal in -lreadline, so I could not test it.

That's a bit weird. I think it should build fine since all of the usages of rl_resize_terminal covered by the HAVE_RL_RESIZE_TERMINAL check. See this for an example. Could you post a little bit more information here?

@nirs
Copy link
Copy Markdown
Contributor Author

nirs commented Jul 10, 2017

The issue is this check in setup.py:

if host_platform == 'darwin':
    os_release = int(os.uname()[2].split('.')[0])
    dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
    if (dep_target and
            (tuple(int(n) for n in dep_target.split('.')[0:2])
                < (10, 5) ) ): 
        os_release = 8
    if os_release < 9: 
        # MacOSX 10.4 has a broken readline. Don't try to build
        # the readline module unless the user has installed a fixed
        # readline package
        if find_file('readline/rlconf.h', inc_dirs, []) is None:
            do_readline = False```

When configuring 2.7, we MACOSX_DEPLOYMENT_TARGET is "10.4", and readline is
disabled. When configuring master/3.6/3.5, we get "10.11", so readline is not disabled.

MACOSX_DEPLOYMENT_TARGET Identifies the earliest OS X version the product is to
run on. So with 2.7 we try to build a version that runs on any OS X version down to 10.4,
and in master/3.x we build only for the current version. I did not find why this happens.

This is also reproducible on travis OS X build, see:
https://travis-ci.org/python/cpython/jobs/251594769

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             dl                 imageop         
linuxaudiodev      ossaudiodev        readline        
spwd               sunaudiodev                        

I think we need to open a separate issue for this, this is not related to this fix, since readline
is not built by default on OS X.

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

The backport lacks the test_readline change, and please use better PR title.

@berkerpeksag
Copy link
Copy Markdown
Member

I think we need to open a separate issue for this, this is not related to this fix, since readline
is not built by default on OS X.

Agreed, could you create a new issue on bugs.p.o?

@nirs nirs changed the title [2.7] bpo-29854: Backport for 2.7 [2.7] bpo-29854: Backport fix for 2.7 (without the test) Jul 10, 2017
@nirs
Copy link
Copy Markdown
Contributor Author

nirs commented Jul 10, 2017

@Haypo, the title is hopefully better now.

@vstinner
Copy link
Copy Markdown
Member

[2.7] bpo-29854: Backport fix for 2.7 (without the test) #2637

Sorry, but this title is still not good. I would prefer "[2.7] bpo-29854: Fix segfault in call_readline()".

Why not backporting the unit test?

@nirs nirs changed the title [2.7] bpo-29854: Backport fix for 2.7 (without the test) [2.7] bpo-29854: Fix segfault in call_readline() Jul 10, 2017
@nirs
Copy link
Copy Markdown
Contributor Author

nirs commented Jul 10, 2017

@Haypo, the test depends on run_pty(), not available in 2.7, and it depends on the selectors module. Too much work for one test.

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

It's ok to not backport the test.

@vstinner
Copy link
Copy Markdown
Member

@berkerpeksag: What do you think?

@berkerpeksag berkerpeksag merged commit bfa4fe4 into python:2.7 Jul 10, 2017
@berkerpeksag
Copy link
Copy Markdown
Member

berkerpeksag commented Jul 10, 2017

@berkerpeksag: What do you think?

Agreed. I just merged the PR. Thank you all!

@nirs nirs deleted the bpo-29854-2.7 branch November 5, 2017 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants