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 #define WIDTH 80
8 #define HEIGHT 24
9
terminal_write_fn(struct tsm_vte * vte,const char * u8,size_t len,void * data)10 static void terminal_write_fn(struct tsm_vte *vte,
11 const char *u8,
12 size_t len,
13 void *data)
14 {
15 // try to access the written data
16 static char out[4096];
17 while (len--)
18 out[len % sizeof(out)] = u8[len];
19 }
20
term_draw_cell(struct tsm_screen * screen,uint32_t id,const uint32_t * ch,size_t len,unsigned int cwidth,unsigned int posx,unsigned int posy,const struct tsm_screen_attr * attr,tsm_age_t age,void * data)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 {
28 if (posx >= WIDTH || posy >= HEIGHT)
29 abort();
30 return 0;
31 }
32
33 // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)34 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
35 struct tsm_screen *screen;
36 struct tsm_vte *vte;
37 const int scrollback_size = 200; // frecon use 200
38
39 tsm_screen_new(&screen, NULL, NULL);
40 tsm_screen_set_max_sb(screen, scrollback_size);
41 tsm_vte_new(&vte, screen, terminal_write_fn, NULL, NULL, NULL);
42 tsm_screen_resize(screen, WIDTH, HEIGHT);
43
44 tsm_vte_input(vte, (const char*) data, size);
45 tsm_screen_draw(screen, term_draw_cell, NULL);
46
47 tsm_vte_unref(vte);
48 tsm_screen_unref(screen);
49 return 0;
50 }
51