test_crash.vim (8504B)
1 " Some tests, that used to crash Vim 2 source check.vim 3 source screendump.vim 4 5 CheckScreendump 6 7 " Run the command in terminal and wait for it to complete via notification 8 func s:RunCommandAndWait(buf, cmd) 9 call term_sendkeys(a:buf, a:cmd .. "; printf '" .. TermNotifyParentCmd(v:false) .. "'\<cr>") 10 if ValgrindOrAsan() 11 " test times out on ASAN CI builds 12 call WaitForChildNotification(10000) 13 else 14 call WaitForChildNotification() 15 endif 16 endfunc 17 18 func Test_crash1() 19 CheckNotBSD 20 CheckExecutable dash 21 22 " The following used to crash Vim 23 let opts = #{cmd: 'sh'} 24 let vim = GetVimProg() 25 26 let buf = RunVimInTerminal('sh', opts) 27 28 let file = 'crash/poc_huaf1' 29 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 30 let args = printf(cmn_args, vim, file) 31 call s:RunCommandAndWait(buf, args .. 32 \ ' && echo "crash 1: [OK]" > X_crash1_result.txt') 33 34 let file = 'crash/poc_huaf2' 35 let args = printf(cmn_args, vim, file) 36 call s:RunCommandAndWait(buf, args .. 37 \ ' && echo "crash 2: [OK]" >> X_crash1_result.txt') 38 39 let file = 'crash/poc_huaf3' 40 let args = printf(cmn_args, vim, file) 41 call s:RunCommandAndWait(buf, args .. 42 \ ' && echo "crash 3: [OK]" >> X_crash1_result.txt') 43 44 let file = 'crash/bt_quickfix_poc' 45 let args = printf(cmn_args, vim, file) 46 call s:RunCommandAndWait(buf, args .. 47 \ ' && echo "crash 4: [OK]" >> X_crash1_result.txt') 48 " clean up 49 call delete('Xerr') 50 51 let file = 'crash/poc_tagfunc.vim' 52 let args = printf(cmn_args, vim, file) 53 " using || because this poc causes vim to exit with exitstatus != 0 54 call s:RunCommandAndWait(buf, args .. 55 \ ' || echo "crash 5: [OK]" >> X_crash1_result.txt') 56 57 58 let file = 'crash/bt_quickfix1_poc' 59 let args = printf(cmn_args, vim, file) 60 call s:RunCommandAndWait(buf, args .. 61 \ ' && echo "crash 6: [OK]" >> X_crash1_result.txt') 62 " clean up 63 call delete('X') 64 65 let file = 'crash/vim_regsub_both_poc' 66 let args = printf(cmn_args, vim, file) 67 call s:RunCommandAndWait(buf, args .. 68 \ ' && echo "crash 7: [OK]" >> X_crash1_result.txt') 69 70 let file = 'crash/vim_msg_trunc_poc' 71 let args = printf(cmn_args, vim, file) 72 call s:RunCommandAndWait(buf, args .. 73 \ ' || echo "crash 8: [OK]" >> X_crash1_result.txt') 74 75 let file = 'crash/crash_scrollbar' 76 let args = printf(cmn_args, vim, file) 77 call s:RunCommandAndWait(buf, args .. 78 \ ' && echo "crash 9: [OK]" >> X_crash1_result.txt') 79 80 let file = 'crash/editing_arg_idx_POC_1' 81 let args = printf(cmn_args, vim, file) 82 call s:RunCommandAndWait(buf, args .. 83 \ ' || echo "crash 10: [OK]" >> X_crash1_result.txt') 84 call delete('Xerr') 85 call delete('@') 86 87 " clean up 88 exe buf .. "bw!" 89 90 sp X_crash1_result.txt 91 92 let expected = [ 93 \ 'crash 1: [OK]', 94 \ 'crash 2: [OK]', 95 \ 'crash 3: [OK]', 96 \ 'crash 4: [OK]', 97 \ 'crash 5: [OK]', 98 \ 'crash 6: [OK]', 99 \ 'crash 7: [OK]', 100 \ 'crash 8: [OK]', 101 \ 'crash 9: [OK]', 102 \ 'crash 10: [OK]', 103 \ ] 104 105 call assert_equal(expected, getline(1, '$')) 106 bw! 107 108 call delete('X_crash1_result.txt') 109 endfunc 110 111 func Test_crash1_2() 112 CheckNotBSD 113 CheckExecutable dash 114 115 " The following used to crash Vim 116 let opts = #{cmd: 'sh'} 117 let vim = GetVimProg() 118 let result = 'X_crash1_2_result.txt' 119 120 let buf = RunVimInTerminal('sh', opts) 121 122 let file = 'crash/poc1' 123 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 124 let args = printf(cmn_args, vim, file) 125 call s:RunCommandAndWait(buf, args .. 126 \ ' && echo "crash 1: [OK]" > '.. result) 127 128 let file = 'crash/poc_win_enter_ext' 129 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 130 let args = printf(cmn_args, vim, file) 131 call s:RunCommandAndWait(buf, args .. 132 \ ' && echo "crash 2: [OK]" >> '.. result) 133 134 let file = 'crash/poc_suggest_trie_walk' 135 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 136 let args = printf(cmn_args, vim, file) 137 call s:RunCommandAndWait(buf, args .. 138 \ ' && echo "crash 3: [OK]" >> '.. result) 139 140 let file = 'crash/poc_did_set_langmap' 141 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'" 142 let args = printf(cmn_args, vim, file) 143 call s:RunCommandAndWait(buf, args .. 144 \ ' ; echo "crash 4: [OK]" >> '.. result) 145 146 let file = 'crash/reverse_text_overflow' 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 s:RunCommandAndWait(buf, args .. 150 \ ' ; echo "crash 5: [OK]" >> '.. result) 151 152 let file = 'Xdiff' 153 let lines =<< trim END 154 diffs a 155 edit Xdiff 156 file b 157 exe "norm! \<C-w>\<C-w>" 158 exe "norm! \<C-w>\<C-w>" 159 exe "norm! \<C-w>\<C-w>" 160 exe "norm! \<C-w>\<C-w>" 161 exe "norm! \<C-w>\<C-w>" 162 exe "norm! \<C-w>\L" 163 exe "norm! \<C-j>oy\<C-j>" 164 edit Xdiff 165 sil!so 166 END 167 call writefile(lines, file, 'D') 168 let cmn_args = "%s -u NONE -i NONE -X -m -n -e -s -u %s -c ':qa!'" 169 let args = printf(cmn_args, vim, file) 170 call s:RunCommandAndWait(buf, args .. 171 \ ' && echo "crash 6: [OK]" >> '.. result) 172 173 174 " clean up 175 exe buf .. "bw!" 176 exe "sp " .. result 177 let expected = [ 178 \ 'crash 1: [OK]', 179 \ 'crash 2: [OK]', 180 \ 'crash 3: [OK]', 181 \ 'crash 4: [OK]', 182 \ 'crash 5: [OK]', 183 \ 'crash 6: [OK]', 184 \ ] 185 186 call assert_equal(expected, getline(1, '$')) 187 bw! 188 call delete(result) 189 endfunc 190 191 " This test just runs various scripts, that caused issues before. 192 " We are not really asserting anything here, it's just important 193 " that ASAN does not detect any issues. 194 func Test_crash1_3() 195 let vim = GetVimProg() 196 let buf = RunVimInTerminal('sh', #{cmd: 'sh'}) 197 198 let file = 'crash/poc_ex_substitute' 199 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 200 let args = printf(cmn_args, vim, file) 201 call s:RunCommandAndWait(buf, args) 202 203 let file = 'crash/poc_uaf_exec_instructions' 204 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 205 let args = printf(cmn_args, vim, file) 206 call s:RunCommandAndWait(buf, args) 207 208 let file = 'crash/poc_uaf_check_argument_types' 209 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 210 let args = printf(cmn_args, vim, file) 211 call s:RunCommandAndWait(buf, args) 212 213 let file = 'crash/double_free' 214 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 215 let args = printf(cmn_args, vim, file) 216 call s:RunCommandAndWait(buf, args) 217 218 let file = 'crash/dialog_changed_uaf' 219 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 220 let args = printf(cmn_args, vim, file) 221 call s:RunCommandAndWait(buf, args) 222 223 let file = 'crash/nullpointer' 224 let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'" 225 let args = printf(cmn_args, vim, file) 226 call s:RunCommandAndWait(buf, args) 227 228 let file = 'crash/heap_overflow3' 229 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'" 230 let args = printf(cmn_args, vim, file) 231 call s:RunCommandAndWait(buf, args) 232 233 let file = 'crash/heap_overflow_glob2regpat' 234 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'" 235 let args = printf(cmn_args, vim, file) 236 call s:RunCommandAndWait(buf, args) 237 238 let file = 'crash/nullptr_regexp_nfa' 239 let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'" 240 let args = printf(cmn_args, vim, file) 241 call s:RunCommandAndWait(buf, args) 242 243 " clean up 244 exe buf .. "bw!" 245 bw! 246 endfunc 247 248 func Test_crash2() 249 CheckScreendump 250 " The following used to crash Vim 251 let opts = #{wait_for_ruler: 0, rows: 20} 252 let args = ' -u NONE -i NONE -n -e -s -S ' 253 let buf = RunVimInTerminal(args .. ' crash/vim_regsub_both', opts) 254 call VerifyScreenDump(buf, 'Test_crash_01', {}) 255 exe buf .. "bw!" 256 endfunc 257 258 func TearDown() 259 " That file is created at Test_crash1_3() by dialog_changed_uaf 260 " but cleaning up in that test doesn't remove it. Let's try again at 261 " the end of this test script 262 call delete('Untitled') 263 endfunc 264 265 func Test_crash_bufwrite() 266 let lines =<< trim END 267 w! ++enc=ucs4 Xoutput 268 call writefile(['done'], 'Xbufwrite') 269 END 270 call writefile(lines, 'Xvimrc') 271 let opts = #{wait_for_ruler: 0, rows: 20} 272 let args = ' -u NONE -i NONE -b -S Xvimrc' 273 let buf = RunVimInTerminal(args .. ' samples/buffer-test.txt', opts) 274 call TermWait(buf, 1000) 275 call StopVimInTerminal(buf) 276 call WaitForAssert({-> assert_true(filereadable('Xbufwrite'))}) 277 call assert_equal(['done'], readfile('Xbufwrite')) 278 call delete('Xbufwrite') 279 call delete('Xoutput') 280 call delete('Xvimrc') 281 endfunc 282 283 " vim: shiftwidth=2 sts=2 expandtab