blob: 302d3730b6b12c0e1d3adcb61bc368c29bcd5779 [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
7func Test_crash1()
Christian Brabandtd2a08ba2023-09-05 07:45:04 +02008 CheckNotBSD
Philip H1690ec62023-09-06 20:20:07 +02009 CheckExecutable dash
Christian Brabandtda200c22023-09-06 21:12:24 +020010 " Test 7 fails on Mac ...
Christian Brabandt5856b072023-09-06 20:53:46 +020011 CheckNotMac
Christian Brabandtd2a08ba2023-09-05 07:45:04 +020012
Christian Brabandte1dc9a62023-09-02 14:40:13 +020013 " The following used to crash Vim
Christian Brabandtdb510ca2023-09-03 09:23:12 +020014 let opts = #{cmd: 'sh'}
Christian Brabandtdb510ca2023-09-03 09:23:12 +020015 let vim = GetVimProg()
16
Christian Brabandtfc682992023-09-03 20:20:52 +020017 let buf = RunVimInTerminal('sh', opts)
Christian Brabandtdb510ca2023-09-03 09:23:12 +020018
19 let file = 'crash/poc_huaf1'
20 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
21 let args = printf(cmn_args, vim, file)
22 call term_sendkeys(buf, args ..
Christian Brabandtfc682992023-09-03 20:20:52 +020023 \ ' && echo "crash 1: [OK]" > X_crash1_result.txt' .. "\<cr>")
24 call TermWait(buf, 50)
Christian Brabandtdb510ca2023-09-03 09:23:12 +020025
26 let file = 'crash/poc_huaf2'
27 let args = printf(cmn_args, vim, file)
28 call term_sendkeys(buf, args ..
29 \ ' && echo "crash 2: [OK]" >> X_crash1_result.txt' .. "\<cr>")
Christian Brabandtfc682992023-09-03 20:20:52 +020030 call TermWait(buf, 50)
Christian Brabandtdb510ca2023-09-03 09:23:12 +020031
32 let file = 'crash/poc_huaf3'
33 let args = printf(cmn_args, vim, file)
34 call term_sendkeys(buf, args ..
35 \ ' && echo "crash 3: [OK]" >> X_crash1_result.txt' .. "\<cr>")
Christian Brabandtfc682992023-09-03 20:20:52 +020036 call TermWait(buf, 100)
Christian Brabandtdb510ca2023-09-03 09:23:12 +020037
Christian Brabandtfc682992023-09-03 20:20:52 +020038 let file = 'crash/bt_quickfix_poc'
39 let args = printf(cmn_args, vim, file)
40 call term_sendkeys(buf, args ..
41 \ ' && echo "crash 4: [OK]" >> X_crash1_result.txt' .. "\<cr>")
42 " clean up
43 call delete('Xerr')
Christian Brabandtfc682992023-09-03 20:20:52 +020044 " This test takes a bit longer
Christian Brabandt623ba312023-09-04 22:09:12 +020045 call TermWait(buf, 1000)
Christian Brabandtdb510ca2023-09-03 09:23:12 +020046
Christian Brabandtee9166e2023-09-03 21:24:33 +020047 let file = 'crash/poc_tagfunc.vim'
48 let args = printf(cmn_args, vim, file)
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020049 " using || because this poc causes vim to exit with exitstatus != 0
Christian Brabandtee9166e2023-09-03 21:24:33 +020050 call term_sendkeys(buf, args ..
51 \ ' || echo "crash 5: [OK]" >> X_crash1_result.txt' .. "\<cr>")
52
53 call TermWait(buf, 100)
54
Christian Brabandt6e60cf42023-09-03 21:43:46 +020055 let file = 'crash/bt_quickfix1_poc'
56 let args = printf(cmn_args, vim, file)
57 call term_sendkeys(buf, args ..
58 \ ' && echo "crash 6: [OK]" >> X_crash1_result.txt' .. "\<cr>")
59 " clean up
60 call delete('X')
Christian Brabandt59adcb42023-09-04 22:42:55 +020061 call TermWait(buf, 3000)
Christian Brabandt6e60cf42023-09-03 21:43:46 +020062
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020063 let file = 'crash/vim_regsub_both_poc'
64 let args = printf(cmn_args, vim, file)
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020065 call term_sendkeys(buf, args ..
66 \ ' && echo "crash 7: [OK]" >> X_crash1_result.txt' .. "\<cr>")
Philip H1690ec62023-09-06 20:20:07 +020067 call TermWait(buf, 3000)
Christian Brabandtf6d28fe2023-09-05 20:18:06 +020068
Christian Brabandt3bd7fa12023-10-02 20:59:08 +020069 let file = 'crash/vim_msg_trunc_poc'
70 let args = printf(cmn_args, vim, file)
71 call term_sendkeys(buf, args ..
72 \ ' || echo "crash 8: [OK]" >> X_crash1_result.txt' .. "\<cr>")
73 call TermWait(buf, 3000)
74
Christian Brabandt20d161a2023-10-05 22:08:30 +020075 let file = 'crash/crash_scrollbar'
76 let args = printf(cmn_args, vim, file)
77 call term_sendkeys(buf, args ..
78 \ ' && echo "crash 9: [OK]" >> X_crash1_result.txt' .. "\<cr>")
79 call TermWait(buf, 1000)
80
Christian Brabandt41e6f7d2023-10-11 21:08:13 +020081 let file = 'crash/editing_arg_idx_POC_1'
82 let args = printf(cmn_args, vim, file)
83 call term_sendkeys(buf, args ..
84 \ ' || echo "crash 10: [OK]" >> X_crash1_result.txt' .. "\<cr>")
85 call TermWait(buf, 1000)
86 call delete('Xerr')
87 call delete('@')
88
Christian Brabandtdb510ca2023-09-03 09:23:12 +020089 " clean up
Christian Brabandte1dc9a62023-09-02 14:40:13 +020090 exe buf .. "bw!"
91
Christian Brabandtdb510ca2023-09-03 09:23:12 +020092 sp X_crash1_result.txt
Christian Brabandtfc682992023-09-03 20:20:52 +020093
94 let expected = [
95 \ 'crash 1: [OK]',
96 \ 'crash 2: [OK]',
97 \ 'crash 3: [OK]',
98 \ 'crash 4: [OK]',
Christian Brabandtee9166e2023-09-03 21:24:33 +020099 \ 'crash 5: [OK]',
Christian Brabandt6e60cf42023-09-03 21:43:46 +0200100 \ 'crash 6: [OK]',
Christian Brabandtf6d28fe2023-09-05 20:18:06 +0200101 \ 'crash 7: [OK]',
Christian Brabandt3bd7fa12023-10-02 20:59:08 +0200102 \ 'crash 8: [OK]',
Christian Brabandt20d161a2023-10-05 22:08:30 +0200103 \ 'crash 9: [OK]',
Christian Brabandt41e6f7d2023-10-11 21:08:13 +0200104 \ 'crash 10: [OK]',
Christian Brabandtfc682992023-09-03 20:20:52 +0200105 \ ]
106
107 call assert_equal(expected, getline(1, '$'))
Christian Brabandtdb510ca2023-09-03 09:23:12 +0200108 bw!
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200109
Christian Brabandtdb510ca2023-09-03 09:23:12 +0200110 call delete('X_crash1_result.txt')
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200111endfunc
112
Christian Brabandt25aabc22023-11-14 19:31:34 +0100113func Test_crash1_2()
114 CheckNotBSD
115 CheckExecutable dash
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100116 let g:test_is_flaky = 1
Christian Brabandt25aabc22023-11-14 19:31:34 +0100117
118 " The following used to crash Vim
119 let opts = #{cmd: 'sh'}
120 let vim = GetVimProg()
Christian Brabandtabfa13e2023-11-30 11:32:18 +0100121 let result = 'X_crash1_2_result.txt'
Christian Brabandt25aabc22023-11-14 19:31:34 +0100122
123 let buf = RunVimInTerminal('sh', opts)
124
125 let file = 'crash/poc1'
126 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
127 let args = printf(cmn_args, vim, file)
128 call term_sendkeys(buf, args ..
129 \ ' && echo "crash 1: [OK]" > '.. result .. "\<cr>")
130 call TermWait(buf, 150)
131
Christian Brabandteec0c2b2023-11-28 22:03:48 +0100132 let file = 'crash/poc_win_enter_ext'
133 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
134 let args = printf(cmn_args, vim, file)
135 call term_sendkeys(buf, args ..
136 \ ' && echo "crash 2: [OK]" >> '.. result .. "\<cr>")
137 call TermWait(buf, 350)
138
Christian Brabandt0fb375a2023-11-29 10:23:39 +0100139 let file = 'crash/poc_suggest_trie_walk'
140 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'"
141 let args = printf(cmn_args, vim, file)
142 call term_sendkeys(buf, args ..
143 \ ' && echo "crash 3: [OK]" >> '.. result .. "\<cr>")
144 call TermWait(buf, 150)
145
Christian Brabandtb39b2402023-11-29 11:34:05 +0100146 let file = 'crash/poc_did_set_langmap'
147 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
148 let args = printf(cmn_args, vim, file)
149 call term_sendkeys(buf, args ..
150 \ ' ; echo "crash 4: [OK]" >> '.. result .. "\<cr>")
151 call TermWait(buf, 150)
152
Christian Brabandtcacb6692024-08-22 21:40:14 +0200153 let file = 'crash/reverse_text_overflow'
154 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
155 let args = printf(cmn_args, vim, file)
156 call term_sendkeys(buf, args ..
157 \ ' ; echo "crash 5: [OK]" >> '.. result .. "\<cr>")
158 call TermWait(buf, 150)
159
Christian Brabandt25aabc22023-11-14 19:31:34 +0100160 " clean up
161 exe buf .. "bw!"
Christian Brabandt25aabc22023-11-14 19:31:34 +0100162 exe "sp " .. result
Christian Brabandt25aabc22023-11-14 19:31:34 +0100163 let expected = [
164 \ 'crash 1: [OK]',
Christian Brabandteec0c2b2023-11-28 22:03:48 +0100165 \ 'crash 2: [OK]',
Christian Brabandt0fb375a2023-11-29 10:23:39 +0100166 \ 'crash 3: [OK]',
Christian Brabandtb39b2402023-11-29 11:34:05 +0100167 \ 'crash 4: [OK]',
Christian Brabandtcacb6692024-08-22 21:40:14 +0200168 \ 'crash 5: [OK]',
Christian Brabandt25aabc22023-11-14 19:31:34 +0100169 \ ]
170
171 call assert_equal(expected, getline(1, '$'))
172 bw!
Christian Brabandt25aabc22023-11-14 19:31:34 +0100173 call delete(result)
174endfunc
175
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100176" This test just runs various scripts, that caused issues before.
177" We are not really asserting anything here, it's just important
178" that ASAN does not detect any issues.
179func Test_crash1_3()
180 let vim = GetVimProg()
181 let buf = RunVimInTerminal('sh', #{cmd: 'sh'})
182
183 let file = 'crash/poc_ex_substitute'
184 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
185 let args = printf(cmn_args, vim, file)
186 call term_sendkeys(buf, args)
187 call TermWait(buf, 150)
188
189 let file = 'crash/poc_uaf_exec_instructions'
190 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
191 let args = printf(cmn_args, vim, file)
192 call term_sendkeys(buf, args)
193 call TermWait(buf, 150)
194
Christian Brabandt0f287912023-12-11 17:53:25 +0100195 let file = 'crash/poc_uaf_check_argument_types'
196 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
197 let args = printf(cmn_args, vim, file)
198 call term_sendkeys(buf, args)
199 call TermWait(buf, 150)
200
Christian Brabandt8a0bbe72024-08-01 20:16:51 +0200201 let file = 'crash/double_free'
202 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
203 let args = printf(cmn_args, vim, file)
204 call term_sendkeys(buf, args)
205 call TermWait(buf, 50)
206
Christian Brabandtb29f4ab2024-08-01 22:10:28 +0200207 let file = 'crash/dialog_changed_uaf'
208 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
209 let args = printf(cmn_args, vim, file)
210 call term_sendkeys(buf, args)
211 call TermWait(buf, 150)
Christian Brabandtcacb6692024-08-22 21:40:14 +0200212 call delete('Untitled')
Christian Brabandtb29f4ab2024-08-01 22:10:28 +0200213
Christian Brabandtfb3f9692024-08-11 20:09:17 +0200214 let file = 'crash/nullpointer'
215 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
216 let args = printf(cmn_args, vim, file)
217 call term_sendkeys(buf, args)
218 call TermWait(buf, 50)
219
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100220 " clean up
221 exe buf .. "bw!"
222 bw!
223endfunc
224
Christian Brabandtced2c732023-09-02 21:15:52 +0200225func Test_crash2()
226 " The following used to crash Vim
227 let opts = #{wait_for_ruler: 0, rows: 20}
228 let args = ' -u NONE -i NONE -n -e -s -S '
229 let buf = RunVimInTerminal(args .. ' crash/vim_regsub_both', opts)
230 call VerifyScreenDump(buf, 'Test_crash_01', {})
231 exe buf .. "bw!"
232endfunc
233
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200234" vim: shiftwidth=2 sts=2 expandtab