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

Crash when error is produced inside try/catch block on CmdlineEnter or CmdlineLeave #7876

Closed
markonm opened this issue Jan 19, 2018 · 4 comments
Assignees
Labels
bug-crash issue reporting a crash or segfault
Milestone

Comments

@markonm
Copy link

markonm commented Jan 19, 2018

  • nvim --version: NVIM v0.2.3-dev
  • Vim (version: ) behaves differently? Yes
  • Operating system/version: Windows 10, WSL

Steps to reproduce using nvim -u NORC

" reproduce.vim
function! s:crash() abort
  try
    gibberish
  catch
    " nop
  endtry
endfunction
autocmd CmdlineEnter,CmdlineLeave : call s:crash()
nvim -u NORC
:so reproduce.vim
:

Actual behaviour

Crash.

nvim: /build/neovim-MwR3Wh/neovim-0.2.0ubuntu1+git201712200021+3828+26~ubuntu16.04.1/src/nvim/api/private/helpers.c:88: try_leave: Assertion `current_exception == NULL' failed.
~                                                       Aborted (core dumped)

Expected behaviour

No crash.

@jamessan
Copy link
Member

jamessan commented Jan 19, 2018

@ZyX-I This is failing in the assert added by 2a6423e.

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007f15c84d5cf7 in __GI_abort () at abort.c:90
#2  0x00007f15c84ccfca in __assert_fail_base (fmt=0x7f15c861d890 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x1bddd20 <.str.7> "current_exception == NULL", file=file@entry=0x1be6398 "../src/nvim/api/private/helpers.c", 
    line=line@entry=88, function=function@entry=0x1bddae0 <__PRETTY_FUNCTION__.try_leave> "_Bool try_leave(const TryState *const, Error *const)")
    at assert.c:92
#3  0x00007f15c84cd042 in __GI___assert_fail (assertion=0x1bddd20 <.str.7> "current_exception == NULL", 
    file=0x1be6398 "../src/nvim/api/private/helpers.c", line=88, 
    function=0x1bddae0 <__PRETTY_FUNCTION__.try_leave> "_Bool try_leave(const TryState *const, Error *const)") at assert.c:101
#4  0x00000000005eb9ae in try_leave (tstate=0x7ffd74e76940, err=0x7ffd74e76990) at ../src/nvim/api/private/helpers.c:88
#5  0x0000000000c5d19c in command_line_enter (firstc=58, count=1, indent=0) at ../src/nvim/ex_getln.c:374
#6  0x0000000000c55d31 in getcmdline (firstc=58, count=1, indent=0) at ../src/nvim/ex_getln.c:1920
#7  0x0000000000c61c56 in getexline (c=58, cookie=0x0, indent=0) at ../src/nvim/ex_getln.c:2100
#8  0x0000000000b7fc21 in do_cmdline (cmdline=0x0, fgetline=0xc61bc0 <getexline>, cookie=0x0, flags=0) at ../src/nvim/ex_docmd.c:528
#9  0x000000000115fa3c in nv_colon (cap=0x7ffd74e79940) at ../src/nvim/normal.c:4552
#10 0x0000000001146a01 in normal_execute (state=0x7ffd74e798a0, key=58) at ../src/nvim/normal.c:1136
#11 0x00000000017d7361 in state_enter (s=0x7ffd74e798a0) at ../src/nvim/state.c:67
#12 0x00000000010fd520 in normal_enter (cmdwin=false, noexmode=false) at ../src/nvim/normal.c:466
#13 0x0000000000edc8da in main (argc=3, argv=0x7ffd74e7a158) at ../src/nvim/main.c:572

@bfredl
Copy link
Member

bfredl commented Jan 19, 2018

I can get the same crash with g:Nvim_color_cmdline using

function! Crash2(cmdline) abort
  try
    gibberish
  catch
    " nop
  endtry
  return []
endfunction
let g:Nvim_color_cmdline = "Crash2"

Otherwise try_leave is not used.

@ZyX-I
Copy link
Contributor

ZyX-I commented Jan 20, 2018

The documentation for current_exception states that it is valid only when did_throw is true which is not the case. I am currently not sure whether I could simply remove that assert(): just doing this has good potential for introducing memory leak.

@ZyX-I
Copy link
Contributor

ZyX-I commented Jan 20, 2018

Ready test for the problem:

diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua
index ffb6a26ae..f9cec903a 100644
--- a/test/functional/ui/cmdline_highlight_spec.lua
+++ b/test/functional/ui/cmdline_highlight_spec.lua
@@ -737,6 +737,22 @@ describe('Command-line coloring', function()
     feed('<CR><CR>')
     eq('', meths.get_var('out'))
   end)
+  it('does not crash when callback has caught not-a-editor-command exception',
+  function()
+    source([[
+      function CaughtExc(cmdline) abort
+        try
+          gibberish
+        catch
+          " Do nothing
+        endtry
+        return []
+      endfunction
+    ]])
+    set_color_cb('CaughtExc')
+    start_prompt('1')
+    eq(1, meths.eval('1'))
+  end)
 end)
 describe('Ex commands coloring support', function()
   it('works', function()

, crashes with

[----------] Global test environment setup.
[----------] Running tests from test/functional/ui/cmdline_highlight_spec.lua
[ RUN      ] Command-line coloring does not crash when callback has caught not-a-editor-command exception: nvim: /home/zyx/a.a/Proj/c/neovim/src/nvim/api/private/helpers.c:88: _Bool try_leave(const TryState *const, Error *const): Assertion `current_exception == NULL' failed.
FAIL
test/functional/ui/cmdline_highlight_spec.lua:754: Expected objects to be the same.
Passed in:
(nil)
Expected:
(number) 1

stack traceback:
        test/functional/ui/cmdline_highlight_spec.lua:754: in function <test/functional/ui/cmdline_highlight_spec.lua:741>

[----------] 1 test from test/functional/ui/cmdline_highlight_spec.lua (529.92 ms total)

[----------] Global test environment teardown.
[==========] 1 test from 1 test file ran. (530.29 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] test/functional/ui/cmdline_highlight_spec.lua @ 740: Command-line coloring does not crash when callback has caught not-a-editor-command exception
test/functional/ui/cmdline_highlight_spec.lua:754: Expected objects to be the same.
Passed in:
(nil)
Expected:
(number) 1

stack traceback:
        test/functional/ui/cmdline_highlight_spec.lua:754: in function <test/functional/ui/cmdline_highlight_spec.lua:741>


 1 FAILED TEST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-crash issue reporting a crash or segfault
Projects
None yet
Development

No branches or pull requests

5 participants