blob: 800f3e5e64df1f3234085b51079a548ef6f84720 [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 Brabandt25aabc22023-11-14 19:31:34 +0100153 " clean up
154 exe buf .. "bw!"
Christian Brabandt25aabc22023-11-14 19:31:34 +0100155 exe "sp " .. result
Christian Brabandt25aabc22023-11-14 19:31:34 +0100156 let expected = [
157 \ 'crash 1: [OK]',
Christian Brabandteec0c2b2023-11-28 22:03:48 +0100158 \ 'crash 2: [OK]',
Christian Brabandt0fb375a2023-11-29 10:23:39 +0100159 \ 'crash 3: [OK]',
Christian Brabandtb39b2402023-11-29 11:34:05 +0100160 \ 'crash 4: [OK]',
Christian Brabandt25aabc22023-11-14 19:31:34 +0100161 \ ]
162
163 call assert_equal(expected, getline(1, '$'))
164 bw!
Christian Brabandt25aabc22023-11-14 19:31:34 +0100165 call delete(result)
166endfunc
167
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100168" This test just runs various scripts, that caused issues before.
169" We are not really asserting anything here, it's just important
170" that ASAN does not detect any issues.
171func Test_crash1_3()
172 let vim = GetVimProg()
173 let buf = RunVimInTerminal('sh', #{cmd: 'sh'})
174
175 let file = 'crash/poc_ex_substitute'
176 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
177 let args = printf(cmn_args, vim, file)
178 call term_sendkeys(buf, args)
179 call TermWait(buf, 150)
180
181 let file = 'crash/poc_uaf_exec_instructions'
182 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
183 let args = printf(cmn_args, vim, file)
184 call term_sendkeys(buf, args)
185 call TermWait(buf, 150)
186
Christian Brabandt0f287912023-12-11 17:53:25 +0100187 let file = 'crash/poc_uaf_check_argument_types'
188 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
189 let args = printf(cmn_args, vim, file)
190 call term_sendkeys(buf, args)
191 call TermWait(buf, 150)
192
Christian Brabandt8a0bbe72024-08-01 20:16:51 +0200193 let file = 'crash/double_free'
194 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
195 let args = printf(cmn_args, vim, file)
196 call term_sendkeys(buf, args)
197 call TermWait(buf, 50)
198
Christian Brabandtb29f4ab2024-08-01 22:10:28 +0200199 let file = 'crash/dialog_changed_uaf'
200 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
201 let args = printf(cmn_args, vim, file)
202 call term_sendkeys(buf, args)
203 call TermWait(buf, 150)
204
Christian Brabandtfb3f9692024-08-11 20:09:17 +0200205 let file = 'crash/nullpointer'
206 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
207 let args = printf(cmn_args, vim, file)
208 call term_sendkeys(buf, args)
209 call TermWait(buf, 50)
210
Christian Brabandt5dd41d42023-12-04 22:52:23 +0100211 " clean up
212 exe buf .. "bw!"
213 bw!
214endfunc
215
Christian Brabandtced2c732023-09-02 21:15:52 +0200216func Test_crash2()
217 " The following used to crash Vim
218 let opts = #{wait_for_ruler: 0, rows: 20}
219 let args = ' -u NONE -i NONE -n -e -s -S '
220 let buf = RunVimInTerminal(args .. ' crash/vim_regsub_both', opts)
221 call VerifyScreenDump(buf, 'Test_crash_01', {})
222 exe buf .. "bw!"
223endfunc
224
Christian Brabandte1dc9a62023-09-02 14:40:13 +0200225" vim: shiftwidth=2 sts=2 expandtab