]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0648: [security] double-free in dialog_changed() v9.1.0648
authorChristian Brabandt <cb@256bit.org>
Thu, 1 Aug 2024 20:10:28 +0000 (22:10 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 1 Aug 2024 20:35:18 +0000 (22:35 +0200)
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 <cb@256bit.org>
src/ex_cmds2.c
src/testdir/crash/dialog_changed_uaf [new file with mode: 0644]
src/testdir/test_crash.vim
src/version.c

index ce30b8d397c00f9eb7f76603afdf80a6daea3301..0d76b3b27aa75fdf3171fc0367e5a865c97c521a 100644 (file)
@@ -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 (file)
index 0000000..e37d18d
Binary files /dev/null and b/src/testdir/crash/dialog_changed_uaf differ
index 29061aa4238fdda184e7add8367ef38cb326b76f..9aef2450267b8a34bfcbb2949c62c2fcfb66fbf8 100644 (file)
@@ -196,6 +196,12 @@ func Test_crash1_3()
   call term_sendkeys(buf, args)
   call TermWait(buf, 50)
 
+  let file = 'crash/dialog_changed_uaf'
+  let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
+  let args = printf(cmn_args, vim, file)
+  call term_sendkeys(buf, args)
+  call TermWait(buf, 150)
+
   " clean up
   exe buf .. "bw!"
   bw!
index 0e49ebd7a05f229d58f2099396ad854a3687b52a..3ca60012693a3c00da4e2f74b23ea252aee114a3 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    648,
 /**/
     647,
 /**/