Coverage Report

Created: 2025-04-22 06:12

/src/libtsm_fuzzer.c
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
45.5M
#define WIDTH 80
8
22.7M
#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
27.0k
{
15
  // try to access the written data
16
27.0k
  static char out[4096];
17
68.4k
  while (len--)
18
41.3k
    out[len % sizeof(out)] = u8[len];
19
27.0k
}
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
22.7M
{
28
22.7M
  if (posx >= WIDTH || posy >= HEIGHT)
29
0
    abort();
30
22.7M
  return 0;
31
22.7M
}
32
33
// Entry point for LibFuzzer.
34
11.8k
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
35
11.8k
  struct tsm_screen *screen;
36
11.8k
  struct tsm_vte *vte;
37
11.8k
  const int scrollback_size = 200;  // frecon use 200
38
39
11.8k
  tsm_screen_new(&screen, NULL, NULL);
40
11.8k
  tsm_screen_set_max_sb(screen, scrollback_size);
41
11.8k
  tsm_vte_new(&vte, screen, terminal_write_fn, NULL, NULL, NULL);
42
11.8k
  tsm_screen_resize(screen, WIDTH, HEIGHT);
43
44
11.8k
  tsm_vte_input(vte, (const char*) data, size);
45
11.8k
  tsm_screen_draw(screen, term_draw_cell, NULL);
46
47
11.8k
  tsm_vte_unref(vte);
48
11.8k
  tsm_screen_unref(screen);
49
11.8k
  return 0;
50
11.8k
}