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