blob: 85b1290d700faea8bab7939a320a492dc38c7835 [file] [log] [blame]
Christian Brabandte1dc9a62023-09-02 14:40:13 +02001" Some tests, that used to crash Vim
2source check.vim
3source screendump.vim
4
5CheckScreendump
6
Yee Cheng Chine70587d2025-02-13 20:55:45 +01007" Run the command in terminal and wait for it to complete via notification
8func s:RunCommandAndWait(buf, cmd)
9 call term_sendkeys(a:buf, a:cmd .. "; printf '" .. TermNotifyParentCmd(v:false) .. "'\<cr>")
10 call WaitForChildNotification()
11endfunc
12
Christian Brabandte1dc9a62023-09-02 14:40:13 +020013func Test_crash1()
Christian Brabandtd2a08ba2023-09-05 07:45:04 +020014 CheckNotBSD
Philip H1690ec62023-09-06 20:20:07 +020015 CheckExecutable dash
Christian Brabandtd2a08ba2023-09-05 07:45:04 +020016
Christian Brabandte1dc9a62023-09-02 14:40:13 +020017 " The following used to crash Vim
Christian Brabandtdb510ca2023-09-03 09:23:12 +020018 let opts = #{cmd: 'sh'}
Christian Brabandtdb510ca2023-09-03 09:23:12 +020019 let vim = GetVimProg()
20
Christian Brabandtfc682992023-09-03 20:20:52 +020021 let buf = RunVimInTerminal('sh', opts)
Christian Brabandtdb510ca2023-09-03 09:23:12 +020022
23 let file = 'crash/poc_huaf1'
24 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
25 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010026 call s:RunCommandAndWait(buf, args ..
27 \ ' && echo "crash 1: [OK]" > X_crash1_result.txt')
Christian Brabandtdb510ca2023-09-03 09:23:12 +020028
29 let file = 'crash/poc_huaf2'
30 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010031 call s:RunCommandAndWait(buf, args ..
32 \ ' && echo "crash 2: [OK]" >> X_crash1_result.txt')
Christian Brabandtdb510ca2023-09-03 09:23:12 +020033
34 let file = 'crash/poc_huaf3'
35 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010036 call s:RunCommandAndWait(buf, args ..
37 \ ' && echo "crash 3: [OK]" >> X_crash1_result.txt')
Christian Brabandtdb510ca2023-09-03 09:23:12 +020038
Christian Brabandtfc682992023-09-03 20:20:52 +020039 let file = 'crash/bt_quickfix_poc'
40 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010041 call s:RunCommandAndWait(buf, args ..
42 \ ' && echo "crash 4: [OK]" >> X_crash1_result.txt')
Christian Brabandtfc682992023-09-03 20:20:52 +020043 " clean up
44 call delete('Xerr')
Christian Brabandtdb510ca2023-09-03 09:23:12 +020045
Christian Brabandtee9166e2023-09-03 21:24:33 +020046 let file = 'crash/poc_tagfunc.vim'
47 let args = printf(cmn_args, vim, file)
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020048 " using || because this poc causes vim to exit with exitstatus != 0
Yee Cheng Chine70587d2025-02-13 20:55:45 +010049 call s:RunCommandAndWait(buf, args ..
50 \ ' || echo "crash 5: [OK]" >> X_crash1_result.txt')
Christian Brabandtee9166e2023-09-03 21:24:33 +020051
Christian Brabandtee9166e2023-09-03 21:24:33 +020052
Christian Brabandt6e60cf42023-09-03 21:43:46 +020053 let file = 'crash/bt_quickfix1_poc'
54 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010055 call s:RunCommandAndWait(buf, args ..
56 \ ' && echo "crash 6: [OK]" >> X_crash1_result.txt')
Christian Brabandt6e60cf42023-09-03 21:43:46 +020057 " clean up
58 call delete('X')
Christian Brabandt6e60cf42023-09-03 21:43:46 +020059
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020060 let file = 'crash/vim_regsub_both_poc'
61 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010062 call s:RunCommandAndWait(buf, args ..
63 \ ' && echo "crash 7: [OK]" >> X_crash1_result.txt')
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020064
Christian Brabandt3bd7fa12023-10-02 20:59:08 +020065 let file = 'crash/vim_msg_trunc_poc'
66 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010067 call s:RunCommandAndWait(buf, args ..
68 \ ' || echo "crash 8: [OK]" >> X_crash1_result.txt')
Christian Brabandt3bd7fa12023-10-02 20:59:08 +020069
Christian Brabandt20d161a2023-10-05 22:08:30 +020070 let file = 'crash/crash_scrollbar'
71 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010072 call s:RunCommandAndWait(buf, args ..
73 \ ' && echo "crash 9: [OK]" >> X_crash1_result.txt')
Christian Brabandt20d161a2023-10-05 22:08:30 +020074
Christian Brabandt41e6f7d2023-10-11 21:08:13 +020075 let file = 'crash/editing_arg_idx_POC_1'
76 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +010077 call s:RunCommandAndWait(buf, args ..
78 \ ' || echo "crash 10: [OK]" >> X_crash1_result.txt')
Christian Brabandt41e6f7d2023-10-11 21:08:13 +020079 call delete('Xerr')
80 call delete('@')
81
Christian Brabandtdb510ca2023-09-03 09:23:12 +020082 " clean up
Christian Brabandte1dc9a62023-09-02 14:40:13 +020083 exe buf .. "bw!"
84
Christian Brabandtdb510ca2023-09-03 09:23:12 +020085 sp X_crash1_result.txt
Christian Brabandtfc682992023-09-03 20:20:52 +020086
87 let expected = [
88 \ 'crash 1: [OK]',
89 \ 'crash 2: [OK]',
90 \ 'crash 3: [OK]',
91 \ 'crash 4: [OK]',
Christian Brabandtee9166e2023-09-03 21:24:33 +020092 \ 'crash 5: [OK]',
Christian Brabandt6e60cf42023-09-03 21:43:46 +020093 \ 'crash 6: [OK]',
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020094 \ 'crash 7: [OK]',
Christian Brabandt3bd7fa12023-10-02 20:59:08 +020095 \ 'crash 8: [OK]',
Christian Brabandt20d161a2023-10-05 22:08:30 +020096 \ 'crash 9: [OK]',
Christian Brabandt41e6f7d2023-10-11 21:08:13 +020097 \ 'crash 10: [OK]',
Christian Brabandtfc682992023-09-03 20:20:52 +020098 \ ]
99
100 call assert_equal(expected, getline(1, '$'))
Christian Brabandtdb510ca2023-09-03 09:23:12 +0200101 bw!
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200102
Christian Brabandtdb510ca2023-09-03 09:23:12 +0200103 call delete('X_crash1_result.txt')
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200104endfunc
105
Christian Brabandt25aabc22023-11-14 19:31:34 +0100106func Test_crash1_2()
107 CheckNotBSD
108 CheckExecutable dash
109
110 " The following used to crash Vim
111 let opts = #{cmd: 'sh'}
112 let vim = GetVimProg()
Christian Brabandtabfa13e2023-11-30 11:32:18 +0100113 let result = 'X_crash1_2_result.txt'
Christian Brabandt25aabc22023-11-14 19:31:34 +0100114
115 let buf = RunVimInTerminal('sh', opts)
116
117 let file = 'crash/poc1'
118 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
119 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100120 call s:RunCommandAndWait(buf, args ..
121 \ ' && echo "crash 1: [OK]" > '.. result)
Christian Brabandt25aabc22023-11-14 19:31:34 +0100122
Christian Brabandteec0c2b2023-11-28 22:03:48 +0100123 let file = 'crash/poc_win_enter_ext'
124 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
125 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100126 call s:RunCommandAndWait(buf, args ..
127 \ ' && echo "crash 2: [OK]" >> '.. result)
Christian Brabandteec0c2b2023-11-28 22:03:48 +0100128
Christian Brabandt0fb375a2023-11-29 10:23:39 +0100129 let file = 'crash/poc_suggest_trie_walk'
130 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
131 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100132 call s:RunCommandAndWait(buf, args ..
133 \ ' && echo "crash 3: [OK]" >> '.. result)
Christian Brabandt0fb375a2023-11-29 10:23:39 +0100134
Christian Brabandtb39b2402023-11-29 11:34:05 +0100135 let file = 'crash/poc_did_set_langmap'
136 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
137 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100138 call s:RunCommandAndWait(buf, args ..
139 \ ' ; echo "crash 4: [OK]" >> '.. result)
Christian Brabandtb39b2402023-11-29 11:34:05 +0100140
Christian Brabandtcacb6692024-08-22 21:40:14 +0200141 let file = 'crash/reverse_text_overflow'
142 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
143 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100144 call s:RunCommandAndWait(buf, args ..
145 \ ' ; echo "crash 5: [OK]" >> '.. result)
Christian Brabandtcacb6692024-08-22 21:40:14 +0200146
Christian Brabandt25aabc22023-11-14 19:31:34 +0100147 " clean up
148 exe buf .. "bw!"
Christian Brabandt25aabc22023-11-14 19:31:34 +0100149 exe "sp " .. result
Christian Brabandt25aabc22023-11-14 19:31:34 +0100150 let expected = [
151 \ 'crash 1: [OK]',
Christian Brabandteec0c2b2023-11-28 22:03:48 +0100152 \ 'crash 2: [OK]',
Christian Brabandt0fb375a2023-11-29 10:23:39 +0100153 \ 'crash 3: [OK]',
Christian Brabandtb39b2402023-11-29 11:34:05 +0100154 \ 'crash 4: [OK]',
Christian Brabandtcacb6692024-08-22 21:40:14 +0200155 \ 'crash 5: [OK]',
Christian Brabandt25aabc22023-11-14 19:31:34 +0100156 \ ]
157
158 call assert_equal(expected, getline(1, '$'))
159 bw!
Christian Brabandt25aabc22023-11-14 19:31:34 +0100160 call delete(result)
161endfunc
162
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100163" This test just runs various scripts, that caused issues before.
164" We are not really asserting anything here, it's just important
165" that ASAN does not detect any issues.
166func Test_crash1_3()
167 let vim = GetVimProg()
168 let buf = RunVimInTerminal('sh', #{cmd: 'sh'})
169
170 let file = 'crash/poc_ex_substitute'
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100171 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100172 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100173 call s:RunCommandAndWait(buf, args)
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100174
175 let file = 'crash/poc_uaf_exec_instructions'
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100176 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100177 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100178 call s:RunCommandAndWait(buf, args)
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100179
Christian Brabandt0f287912023-12-11 17:53:25 +0100180 let file = 'crash/poc_uaf_check_argument_types'
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100181 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
Christian Brabandt0f287912023-12-11 17:53:25 +0100182 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100183 call s:RunCommandAndWait(buf, args)
Christian Brabandt0f287912023-12-11 17:53:25 +0100184
Christian Brabandt8a0bbe72024-08-01 20:16:51 +0200185 let file = 'crash/double_free'
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100186 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
Christian Brabandt8a0bbe72024-08-01 20:16:51 +0200187 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100188 call s:RunCommandAndWait(buf, args)
Christian Brabandt8a0bbe72024-08-01 20:16:51 +0200189
Christian Brabandtb29f4ab2024-08-01 22:10:28 +0200190 let file = 'crash/dialog_changed_uaf'
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100191 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
Christian Brabandtb29f4ab2024-08-01 22:10:28 +0200192 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100193 call s:RunCommandAndWait(buf, args)
Christian Brabandtb29f4ab2024-08-01 22:10:28 +0200194
Christian Brabandtfb3f9692024-08-11 20:09:17 +0200195 let file = 'crash/nullpointer'
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100196 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
Christian Brabandtfb3f9692024-08-11 20:09:17 +0200197 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100198 call s:RunCommandAndWait(buf, args)
Christian Brabandtfb3f9692024-08-11 20:09:17 +0200199
Christian Brabandt322ba912024-08-25 21:33:03 +0200200 let file = 'crash/heap_overflow3'
201 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
202 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100203 call s:RunCommandAndWait(buf, args)
Christian Brabandt322ba912024-08-25 21:33:03 +0200204
Christian Brabandtc9bfed22024-08-29 22:12:05 +0200205 let file = 'crash/heap_overflow_glob2regpat'
206 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
207 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100208 call s:RunCommandAndWait(buf, args)
Christian Brabandt1c815b52024-08-28 22:08:35 +0200209
Christian Brabandtc3a02d72024-08-28 23:17:52 +0200210 let file = 'crash/nullptr_regexp_nfa'
211 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
212 let args = printf(cmn_args, vim, file)
Yee Cheng Chine70587d2025-02-13 20:55:45 +0100213 call s:RunCommandAndWait(buf, args)
Christian Brabandt9d1bed52025-01-20 22:55:57 +0100214
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100215 " clean up
216 exe buf .. "bw!"
217 bw!
218endfunc
219
Christian Brabandtced2c732023-09-02 21:15:52 +0200220func Test_crash2()
221 " The following used to crash Vim
222 let opts = #{wait_for_ruler: 0, rows: 20}
223 let args = ' -u NONE -i NONE -n -e -s -S '
224 let buf = RunVimInTerminal(args .. ' crash/vim_regsub_both', opts)
225 call VerifyScreenDump(buf, 'Test_crash_01', {})
226 exe buf .. "bw!"
227endfunc
228
zeertzjqd56c4512024-08-26 18:45:37 +0200229func TearDown()
230 " That file is created at Test_crash1_3() by dialog_changed_uaf
231 " but cleaning up in that test doesn't remove it. Let's try again at
Christian Brabandtcd831732024-08-24 17:34:19 +0200232 " the end of this test script
233 call delete('Untitled')
234endfunc
235
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200236" vim: shiftwidth=2 sts=2 expandtab