Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | // Copyright 2016 The Chromium Authors. All rights reserved.  | 
2  |  | // Use of this source code is governed by a BSD-style license that can be  | 
3  |  | // found in the LICENSE file.  | 
4  |  |  | 
5  |  | #include "libtsm.h"  | 
6  |  |  | 
7  | 48.3M  | #define WIDTH 80  | 
8  | 24.1M  | #define HEIGHT 24  | 
9  |  |  | 
10  |  | static void terminal_write_fn(struct tsm_vte *vte,  | 
11  |  |             const char *u8,  | 
12  |  |             size_t len,  | 
13  |  |             void *data)  | 
14  | 37.5k  | { | 
15  |  |   // try to access the written data  | 
16  | 37.5k  |   static char out[4096];  | 
17  | 85.3k  |   while (len--)  | 
18  | 47.8k  |     out[len % sizeof(out)] = u8[len];  | 
19  | 37.5k  | }  | 
20  |  |  | 
21  |  | static int term_draw_cell(struct tsm_screen *screen, uint32_t id,  | 
22  |  |                           const uint32_t *ch, size_t len,  | 
23  |  |                           unsigned int cwidth, unsigned int posx,  | 
24  |  |                           unsigned int posy,  | 
25  |  |                           const struct tsm_screen_attr *attr,  | 
26  |  |                           tsm_age_t age, void *data)  | 
27  | 24.1M  | { | 
28  | 24.1M  |   if (posx >= WIDTH || posy >= HEIGHT)  | 
29  | 0  |     abort();  | 
30  | 24.1M  |   return 0;  | 
31  | 24.1M  | }  | 
32  |  |  | 
33  |  | // Entry point for LibFuzzer.  | 
34  | 12.5k  | int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 
35  | 12.5k  |   struct tsm_screen *screen;  | 
36  | 12.5k  |   struct tsm_vte *vte;  | 
37  | 12.5k  |   const int scrollback_size = 200;  // frecon use 200  | 
38  |  |  | 
39  | 12.5k  |   tsm_screen_new(&screen, NULL, NULL);  | 
40  | 12.5k  |   tsm_screen_set_max_sb(screen, scrollback_size);  | 
41  | 12.5k  |   tsm_vte_new(&vte, screen, terminal_write_fn, NULL, NULL, NULL);  | 
42  | 12.5k  |   tsm_screen_resize(screen, WIDTH, HEIGHT);  | 
43  |  |  | 
44  | 12.5k  |   tsm_vte_input(vte, (const char*) data, size);  | 
45  | 12.5k  |   tsm_screen_draw(screen, term_draw_cell, NULL);  | 
46  |  |  | 
47  | 12.5k  |   tsm_vte_unref(vte);  | 
48  | 12.5k  |   tsm_screen_unref(screen);  | 
49  | 12.5k  |   return 0;  | 
50  | 12.5k  | }  |