From b29f4abcd4b3382fa746edd1d0562b7b48c9de60 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Thu, 1 Aug 2024 22:10:28 +0200 Subject: [PATCH] patch 9.1.0648: [security] double-free in dialog_changed() Problem: [security] double-free in dialog_changed() (SuyueGuo) Solution: Only clear pointer b_sfname pointer, if it is different than the b_ffname pointer. Don't try to free b_fname, set it to NULL instead. fixes: #15403 Github Advisory: https://github.com/vim/vim/security/advisories/GHSA-46pw-v7qw-xc2f Signed-off-by: Christian Brabandt --- src/ex_cmds2.c | 6 ++++-- src/testdir/crash/dialog_changed_uaf | Bin 0 -> 552 bytes src/testdir/test_crash.vim | 6 ++++++ src/version.c | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/testdir/crash/dialog_changed_uaf diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index ce30b8d397..0d76b3b27a 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -197,9 +197,11 @@ dialog_changed( // restore to empty when write failed if (empty_bufname) { - VIM_CLEAR(buf->b_fname); + // prevent double free + if (buf->b_sfname != buf->b_ffname) + VIM_CLEAR(buf->b_sfname); + buf->b_fname = NULL; VIM_CLEAR(buf->b_ffname); - VIM_CLEAR(buf->b_sfname); unchanged(buf, TRUE, FALSE); } } diff --git a/src/testdir/crash/dialog_changed_uaf b/src/testdir/crash/dialog_changed_uaf new file mode 100644 index 0000000000000000000000000000000000000000..e37d18d6daca107697bd19934b34054aa09e48a4 GIT binary patch literal 552 zc-noC!A{gb7=ZsSVA4Nz`lOEb_XQfzXmQI(h zB_W$|Q|}&p0gqgG09c>IH^2vQY{3M*_+2KMf0FsW-;3+@IuRCkT?KsheM9>PYxf3_ zKdV@O^#&P_54@<-*s*MNE}G?)x#?mw9{(6$b6}b#>1NrtU6y5b+qTba+up+U*Bj5* zZ|@@?Q-P6y0s?@8#+s@sOG}Kgea4(x;&lZ!-L@7lBMo1${9g#LG?KD zuw8H-;*^wAhjAC3GsU{vnl$h4~CQoGC31~URzjbO#