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