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

Python readline module crashes in history_get on FreeBSD with libedit #68576

Closed
emaste mannequin opened this issue Jun 5, 2015 · 4 comments
Closed

Python readline module crashes in history_get on FreeBSD with libedit #68576

emaste mannequin opened this issue Jun 5, 2015 · 4 comments
Labels
extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@emaste
Copy link
Mannequin

emaste mannequin commented Jun 5, 2015

BPO 24388
Nosy @ned-deily, @vadmium, @DonnaDia
Superseder
  • bpo-13501: Make libedit support more generic; port readline / libedit to FreeBSD
  • Files
  • readline.diff: Initial patch to extend libedit compatibility to FreeBSD
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-06-06.01:57:22.827>
    created_at = <Date 2015-06-05.23:10:28.503>
    labels = ['extension-modules', 'type-crash']
    title = 'Python readline module crashes in history_get on FreeBSD with libedit'
    updated_at = <Date 2021-08-28.20:17:54.278>
    user = 'https://bugs.python.org/emaste'

    bugs.python.org fields:

    activity = <Date 2021-08-28.20:17:54.278>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-06-06.01:57:22.827>
    closer = 'ned.deily'
    components = ['Extension Modules']
    creation = <Date 2015-06-05.23:10:28.503>
    creator = 'emaste'
    dependencies = []
    files = ['39635']
    hgrepos = []
    issue_num = 24388
    keywords = ['patch']
    message_count = 4.0
    messages = ['244877', '244878', '244879', '244881']
    nosy_count = 4.0
    nosy_names = ['ned.deily', 'martin.panter', 'emaste', 'DonnaDia']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '13501'
    type = 'crash'
    url = 'https://bugs.python.org/issue24388'
    versions = ['Python 2.7']

    @emaste
    Copy link
    Mannequin Author

    emaste mannequin commented Jun 5, 2015

    I encountered a segfault in Python's call_readline from LLDB on FreeBSD, with libedit. There is a fix for this issue already in readline.c, but under #ifdef __APPLE__

    Backtrace:

    (lldb) target create "/data/emaste/src/llvm/build/bin/lldb" --core "lldb-3.7.0.core"
    Core file '/tank/emaste/projects/lldb-talk/demo/lldb-3.7.0.core' (x86_64) was loaded.
    (lldb) bt

    • thread Support "bpo-" in Misc/NEWS #1: tid = 0, 0x0000000809706dcd readline.so`call_readline(sys_stdin=0x00000008055d9d10, sys_stdout=0x00000008055d9e40, prompt=0x0000000806eb7854) + 397 at readline.c:1132, name = 'lldb-3.7.0', stop reason = signal SIGSEGV
      • frame #0: 0x0000000809706dcd readline.socall_readline(sys_stdin=0x00000008055d9d10, sys_stdout=0x00000008055d9e40, prompt=0x0000000806eb7854) + 397 at readline.c:1132 frame #1: 0x0000000805c48f1f libpython2.7.so.1PyOS_Readline(sys_stdin=0x00000008055d9d10, sys_stdout=0x00000008055d9e40, prompt=0x0000000806eb7854) + 383 at myreadline.c:207
        frame Rename README to README.rst and enhance formatting #2: 0x0000000805d7f94f libpython2.7.so.1builtin_raw_input(self=0x0000000000000000, args=0x000000080bec1df0) + 639 at bltinmodule.c:2060 frame #3: 0x0000000805cce5c6 libpython2.7.so.1PyCFunction_Call(func=0x00000008007b78d0, arg=0x000000080bec1df0, kw=0x0000000000000000) + 166 at methodobject.c:81
        frame Update Python Software Foundation Copyright Year. #4: 0x0000000805d992aa libpython2.7.so.1call_function(pp_stack=0x00007fffffffbcd0, oparg=1) + 1754 at ceval.c:4033 frame #5: 0x0000000805d93538 libpython2.7.so.1PyEval_EvalFrameEx(f=0x0000000806ecfdf0, throwflag=0) + 51160 at ceval.c:2679
        frame Add Pycharm's .idea directory to gitignore #6: 0x0000000805d86c54 libpython2.7.so.1PyEval_EvalCodeEx(co=0x0000000805a6af60, globals=0x0000000806f9a580, locals=0x0000000000000000, args=0x000000080a06c670, argcount=2, kws=0x000000080a06c680, kwcount=0, defs=0x0000000805aaeda8, defcount=1, closure=0x0000000000000000) + 5284 at ceval.c:3265 frame #7: 0x0000000805d9c2b6 libpython2.7.so.1fast_function(func=0x0000000806f7da38, pp_stack=0x00007fffffffc520, n=2, na=2, nk=0) + 822 at ceval.c:4129
        frame Change some mercurial/ hg.python.org references. #8: 0x0000000805d994c8 libpython2.7.so.1call_function(pp_stack=0x00007fffffffc520, oparg=1) + 2296 at ceval.c:4054 frame #9: 0x0000000805d93538 libpython2.7.so.1PyEval_EvalFrameEx(f=0x000000080a06c4b0, throwflag=0) + 51160 at ceval.c:2679
        frame bpo-29474: Improve documentation for weakref.WeakValueDictionary #10: 0x0000000805d86c54 libpython2.7.so.1PyEval_EvalCodeEx(co=0x0000000805a5ebf0, globals=0x0000000806f9a580, locals=0x0000000000000000, args=0x000000080a06c3e0, argcount=2, kws=0x000000080a06c3f0, kwcount=0, defs=0x0000000805aaecc8, defcount=1, closure=0x0000000000000000) + 5284 at ceval.c:3265 frame #11: 0x0000000805d9c2b6 libpython2.7.so.1fast_function(func=0x0000000806f7d8e8, pp_stack=0x00007fffffffcd70, n=2, na=2, nk=0) + 822 at ceval.c:4129
        frame bpo-29524: Add Objects/call.c file #12: 0x0000000805d994c8 libpython2.7.so.1call_function(pp_stack=0x00007fffffffcd70, oparg=1) + 2296 at ceval.c:4054 frame #13: 0x0000000805d93538 libpython2.7.so.1PyEval_EvalFrameEx(f=0x000000080a06c230, throwflag=0) + 51160 at ceval.c:2679
        frame Disable Travis docs job until a fix is found #14: 0x0000000805d86c54 libpython2.7.so.1PyEval_EvalCodeEx(co=0x0000000805a869e0, globals=0x0000000806f9a580, locals=0x0000000000000000, args=0x000000080a06b9f8, argcount=0, kws=0x000000080a06b9f8, kwcount=2, defs=0x00000008009af688, defcount=3, closure=0x0000000000000000) + 5284 at ceval.c:3265 frame #15: 0x0000000805d9c2b6 libpython2.7.so.1fast_function(func=0x0000000806f7d300, pp_stack=0x00007fffffffd5c0, n=4, na=0, nk=2) + 822 at ceval.c:4129
        frame Make Travis docs build more lenient #16: 0x0000000805d994c8 libpython2.7.so.1call_function(pp_stack=0x00007fffffffd5c0, oparg=512) + 2296 at ceval.c:4054 frame #17: 0x0000000805d93538 libpython2.7.so.1PyEval_EvalFrameEx(f=0x000000080a06b830, throwflag=0) + 51160 at ceval.c:2679
        frame Rename Doc/README.txt to Doc/README.rst #18: 0x0000000805d9c16a libpython2.7.so.1fast_function(func=0x0000000806f9d300, pp_stack=0x00007fffffffdbd0, n=1, na=1, nk=0) + 490 at ceval.c:4119 frame #19: 0x0000000805d994c8 libpython2.7.so.1call_function(pp_stack=0x00007fffffffdbd0, oparg=1) + 2296 at ceval.c:4054
        frame Update link destination of the Mersenne Twister homepage #20: 0x0000000805d93538 libpython2.7.so.1PyEval_EvalFrameEx(f=0x000000080098c9c0, throwflag=0) + 51160 at ceval.c:2679 frame #21: 0x0000000805d86c54 libpython2.7.so.1PyEval_EvalCodeEx(co=0x00000008008ffa90, globals=0x00000008007d8580, locals=0x00000008007d8580, args=0x0000000000000000, argcount=0, kws=0x0000000000000000, kwcount=0, defs=0x0000000000000000, defcount=0, closure=0x0000000000000000) + 5284 at ceval.c:3265
        frame [backport to 3.6] bpo-29474: Improve documentation for weakref.WeakValueDictionary #22: 0x0000000805d857a5 libpython2.7.so.1PyEval_EvalCode(co=0x00000008008ffa90, globals=0x00000008007d8580, locals=0x00000008007d8580) + 85 at ceval.c:667 frame #23: 0x0000000805dd4a15 libpython2.7.so.1run_mod(mod=0x000000080a14f128, filename=0x0000000805e22022, globals=0x00000008007d8580, locals=0x00000008007d8580, flags=0x0000000000000000, arena=0x000000080a027800) + 101 at pythonrun.c:1371
        frame bpo-28837: Fix lib2to3 handling of map/zip/filter #24: 0x0000000805dd50a4 libpython2.7.so.1PyRun_StringFlags(str=0x000000080a0ff820, start=257, globals=0x00000008007d8580, locals=0x00000008007d8580, flags=0x0000000000000000) + 148 at pythonrun.c:1334 frame #25: 0x0000000805dd4f54 libpython2.7.so.1PyRun_SimpleStringFlags(command=0x000000080a0ff820, flags=0x0000000000000000) + 100 at pythonrun.c:975
        frame [backport to 3.5] bpo-29529: Add .travis.yml to 3.5 branch #26: 0x0000000802085fa4 liblldb.so.3.7IOHandlerPythonInterpreter::Run() + 324 frame #27: 0x0000000801f78c12 liblldb.so.3.7lldb_private::Debugger::ExecuteIOHandlers() + 162
        frame bpo-28556: Various updates to typing #28: 0x000000080206635e liblldb.so.3.7lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool, lldb_private::CommandInterpreterRunOptions&) + 126 frame #29: 0x00000008012bc79f liblldb.so.3.7lldb::SBDebugger::RunCommandInterpreter(bool, bool) + 63
        frame Allow up to a 0.01% drop in coverage #30: 0x0000000000406546 lldbDriver::MainLoop() + 2454 frame #31: 0x0000000000406a17 lldbmain + 439
        frame bpo-29576: Improve some deprecations in the importlib #32: 0x000000000040362f lldb`_start + 367

    frame #0: 0x0000000809706dcd readline.so`call_readline(sys_stdin=0x00000008055d9d10, sys_stdout=0x00000008055d9e40, prompt=0x0000000806eb7854) + 397 at readline.c:1132
    1129 line = history_get(length + libedit_history_start - 1)->line;
    1130 } else
    1131 #endif /* __APPLE__ */
    -> 1132 line = history_get(length)->line;
    1133 else
    1134 line = "";
    1135 if (strcmp(p, line))

    It looks like a straightforward s/#ifdef __APPLE__/#if defined(APPLE) || defined(FreeBSD)/ fixes the issue (as in the attached proof of concept patch).

    @emaste emaste mannequin added the extension-modules C modules in the Modules dir label Jun 5, 2015
    @emaste
    Copy link
    Mannequin Author

    emaste mannequin commented Jun 5, 2015

    Presumably the #ifdefs ought to just be deleted though, relying on the runtime detection of libedit compatibility issues on any platform.

    @vadmium
    Copy link
    Member

    vadmium commented Jun 6, 2015

    See also bpo-13501 for a more platform-independent approach.

    I think this crash is actually due to a bug in Editline (later fixed; see bpo-18458), but since Python already has the workaround, it makes sense to use the workaround if necessary for Free BSD, or maybe even in general.

    @vadmium vadmium added the type-crash A hard crash of the interpreter, possibly with a core dump label Jun 6, 2015
    @ned-deily
    Copy link
    Member

    The change in spec in editline was to better match GNU readline behavior. Unfortunately, we depended on the old behavior. Technically, we don't support editline out-of-the-box other than on OS X; as Martin notes, generalizing that support is what bpo-13501 is about. I'm going to close this as a duplicate of it.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants