Mercurial > vim
annotate src/testdir/test_matchadd_conceal_utf8.vim @ 33811:06219b3bdaf3 v9.0.2121
patch 9.0.2121: [security]: use-after-free in ex_substitute
Commit: https://github.com/vim/vim/commit/26c11c56888d01e298cd8044caf860f3c26f57bb
Author: Christian Brabandt <cb@256bit.org>
Date: Wed Nov 22 21:26:41 2023 +0100
patch 9.0.2121: [security]: use-after-free in ex_substitute
Problem: [security]: use-after-free in ex_substitute
Solution: always allocate memory
closes: #13552
A recursive :substitute command could cause a heap-use-after free in Vim
(CVE-2023-48706).
The whole reproducible test is a bit tricky, I can only reproduce this
reliably when no previous substitution command has been used yet
(which is the reason, the test needs to run as first one in the
test_substitute.vim file) and as a combination of the `:~` command
together with a :s command that contains the special substitution atom `~\=`
which will make use of a sub-replace special atom and calls a vim script
function.
There was a comment in the existing :s code, that already makes the
`sub` variable allocate memory so that a recursive :s call won't be able
to cause any issues here, so this was known as a potential problem
already. But for the current test-case that one does not work, because
the substitution does not start with `\=` but with `~\=` (and since
there does not yet exist a previous substitution atom, Vim will simply
increment the `sub` pointer (which then was not allocated dynamically)
and later one happily use a sub-replace special expression (which could
then free the `sub` var).
The following commit fixes this, by making the sub var always using
allocated memory, which also means we need to free the pointer whenever
we leave the function. Since sub is now always an allocated variable,
we also do no longer need the sub_copy variable anymore, since this one
was used to indicated when sub pointed to allocated memory (and had
therefore to be freed on exit) and when not.
Github Security Advisory:
https://github.com/vim/vim/security/advisories/GHSA-c8qm-x72m-q53q
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 22 Nov 2023 22:15:05 +0100 |
parents | 08940efa6b4e |
children |
rev | line source |
---|---|
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test for matchadd() and conceal feature using utf-8. |
17049
f38fcbf343ce
patch 8.1.1524: tests are silently skipped
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2 |
17089
8e9e9124c7a2
patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents:
17049
diff
changeset
|
3 source check.vim |
8e9e9124c7a2
patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents:
17049
diff
changeset
|
4 CheckFeature conceal |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 if !has('gui_running') && has('unix') |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 set term=ansi |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 endif |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
9618
diff
changeset
|
10 func s:screenline(lnum) abort |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 let line = [] |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 for c in range(1, winwidth(0)) |
17994
0dcc2ee838dd
patch 8.1.1993: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17089
diff
changeset
|
13 call add(line, nr2char(a:lnum->screenchar(c))) |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 endfor |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 return s:trim(join(line, '')) |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
9618
diff
changeset
|
16 endfunc |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
9618
diff
changeset
|
18 func s:trim(str) abort |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$') |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
9618
diff
changeset
|
20 endfunc |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
9618
diff
changeset
|
22 func Test_match_using_multibyte_conceal_char() |
8907
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 new |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 setlocal concealcursor=n conceallevel=1 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 1put='# This is a Test' |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 " 1234567890123456 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 let expect = '#ˑThisˑisˑaˑTest' |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 call cursor(1, 1) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"}) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 redraw! |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 let lnum = 2 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 call assert_equal(expect, s:screenline(lnum)) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 |
5deb9e8f4292
commit https://github.com/vim/vim/commit/4d585022023b96f6507e8cae5ed8fc8d926f5140
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 quit! |
15406
63b02fcf1361
patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents:
9618
diff
changeset
|
43 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
17994
diff
changeset
|
44 |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
17994
diff
changeset
|
45 " vim: shiftwidth=2 sts=2 expandtab |