Skip to content

Commit 1ccf338

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.2.0724: Use-after-free when freeing exit_cb job on exit
Problem: Use-after-free when freeing exit_cb job on exit Solution: Return when def_functions has been freed already (Foxe Chen) closes: #20621 Signed-off-by: Foxe Chen <chen.foxe@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 5fdb44c commit 1ccf338

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import './util/vim9.vim' as v9
44
source util/screendump.vim
5+
source util/shared.vim
56

67
func Test_def_basic()
78
def SomeFunc(): string
@@ -5045,4 +5046,27 @@ def Test_void_method_chain()
50455046
v9.CheckScriptFailure(lines, 'E1186: Expression does not result in a value: bufload(')
50465047
enddef
50475048

5049+
def Test_term_wait_in_job_exit_cb()
5050+
CheckUnix
5051+
CheckFeature terminal
5052+
5053+
var cmd = g:GetVimCommand()
5054+
5055+
var lines =<< eval trim END
5056+
var buf: number = term_start(["{cmd}", "+q"], {{}})
5057+
5058+
var job: job = term_getjob(buf)
5059+
5060+
job_setoptions(job, {{
5061+
exit_cb: (_, _) => {{
5062+
term_wait(buf)
5063+
}}
5064+
}})
5065+
END
5066+
5067+
# This shouldn't cause an ASAN error immediately, but will result in a use
5068+
# after free when Vim exits.
5069+
v9.CheckDefSuccess(lines)
5070+
enddef
5071+
50485072
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ static char *(features[]) =
759759

760760
static int included_patches[] =
761761
{ /* Add new patch number below this line */
762+
/**/
763+
724,
762764
/**/
763765
723,
764766
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5238,7 +5238,7 @@ delete_def_function_contents(dfunc_T *dfunc, int mark_deleted)
52385238
void
52395239
unlink_def_function(ufunc_T *ufunc)
52405240
{
5241-
if (ufunc->uf_dfunc_idx <= 0)
5241+
if (ufunc->uf_dfunc_idx <= 0 || def_functions.ga_data == NULL)
52425242
return;
52435243

52445244
dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)

0 commit comments

Comments
 (0)