|
| 1 | +Modified patch to apply to older version |
| 2 | +Modifed by: sumsharma@microsoft.com |
| 3 | + |
| 4 | +From 8a0bbe7b8aad6f8da28dee218c01bc8a0185a2d5 Mon Sep 17 00:00:00 2001 |
| 5 | +From: Christian Brabandt <cb@256bit.org> |
| 6 | +Date: Thu, 1 Aug 2024 20:16:51 +0200 |
| 7 | +Subject: [PATCH] patch 9.1.0647: [security] use-after-free in |
| 8 | + tagstack_clear_entry |
| 9 | + |
| 10 | +Problem: [security] use-after-free in tagstack_clear_entry |
| 11 | + (Suyue Guo ) |
| 12 | +Solution: Instead of manually calling vim_free() on each of the tagstack |
| 13 | + entries, let's use tagstack_clear_entry(), which will |
| 14 | + also free the stack, but using the VIM_CLEAR macro, |
| 15 | + which prevents a use-after-free by setting those pointers |
| 16 | + to NULL |
| 17 | + |
| 18 | +This addresses CVE-2024-41957 |
| 19 | + |
| 20 | +Github advisory: |
| 21 | +https://github.com/vim/vim/security/advisories/GHSA-f9cr-gv85-hcr4 |
| 22 | + |
| 23 | +Signed-off-by: Christian Brabandt <cb@256bit.org> |
| 24 | +--- |
| 25 | + src/proto/tag.pro | 1 + |
| 26 | + src/tag.c | 4 ++-- |
| 27 | + src/window.c | 6 ++---- |
| 28 | + 3 files changed, 5 insertions(+), 6 deletions(-) |
| 29 | + |
| 30 | +diff --git a/src/proto/tag.pro b/src/proto/tag.pro |
| 31 | +index 6de463e..eec7c24 100644 |
| 32 | +--- a/src/proto/tag.pro |
| 33 | ++++ b/src/proto/tag.pro |
| 34 | +@@ -14,4 +14,5 @@ int expand_tags(int tagnames, char_u *pat, int *num_file, char_u ***file); |
| 35 | + int get_tags(list_T *list, char_u *pat, char_u *buf_fname); |
| 36 | + void get_tagstack(win_T *wp, dict_T *retdict); |
| 37 | + int set_tagstack(win_T *wp, dict_T *d, int action); |
| 38 | ++void tagstack_clear_entry(taggy_T *item); |
| 39 | + /* vim: set ft=c : */ |
| 40 | +diff --git a/src/tag.c b/src/tag.c |
| 41 | +index 8003156..31b89e7 100644 |
| 42 | +--- a/src/tag.c |
| 43 | ++++ b/src/tag.c |
| 44 | +@@ -144,7 +144,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char_ |
| 45 | + #if defined(FEAT_QUICKFIX) && defined(FEAT_EVAL) |
| 46 | + static int add_llist_tags(char_u *tag, int num_matches, char_u **matches); |
| 47 | + #endif |
| 48 | +-static void tagstack_clear_entry(taggy_T *item); |
| 49 | ++void tagstack_clear_entry(taggy_T *item); |
| 50 | + |
| 51 | + static char_u *tagmatchname = NULL; // name of last used tag |
| 52 | + |
| 53 | +@@ -4225,7 +4225,7 @@ find_extra(char_u **pp) |
| 54 | + /* |
| 55 | + * Free a single entry in a tag stack |
| 56 | + */ |
| 57 | +- static void |
| 58 | ++void |
| 59 | + tagstack_clear_entry(taggy_T *item) |
| 60 | + { |
| 61 | + VIM_CLEAR(item->tagname); |
| 62 | +diff --git a/src/window.c b/src/window.c |
| 63 | +index 55ce31c..ffffde8 100644 |
| 64 | +--- a/src/window.c |
| 65 | ++++ b/src/window.c |
| 66 | +@@ -5661,10 +5661,8 @@ win_free( |
| 67 | + win_free_lsize(wp); |
| 68 | + |
| 69 | + for (i = 0; i < wp->w_tagstacklen; ++i) |
| 70 | +- { |
| 71 | +- vim_free(wp->w_tagstack[i].tagname); |
| 72 | +- vim_free(wp->w_tagstack[i].user_data); |
| 73 | +- } |
| 74 | ++ tagstack_clear_entry(&wp->w_tagstack[i]); |
| 75 | ++ |
| 76 | + vim_free(wp->w_localdir); |
| 77 | + vim_free(wp->w_prevdir); |
| 78 | + |
| 79 | +-- |
| 80 | +2.25.1 |
| 81 | + |
0 commit comments