Coverage Report

Created: 2026-04-27 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tmux/fuzz/style-fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2026 David Korczynski <david@adalogics.com>
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
/*
18
 * Fuzz the tmux style parser (style_parse).
19
 *
20
 * This exercises:
21
 *   - style.c (style string parsing, alignment, ranges)
22
 *   - colour.c (colour name, RGB, and indexed colour parsing)
23
 */
24
25
#include <stddef.h>
26
#include <string.h>
27
28
#include "tmux.h"
29
30
struct event_base *libevent;
31
32
int
33
LLVMFuzzerTestOneInput(const u_char *data, size_t size)
34
3.55k
{
35
3.55k
  struct style     sy;
36
3.55k
  struct grid_cell   gc;
37
3.55k
  char      *buf;
38
39
3.55k
  if (size > 512 || size == 0)
40
0
    return 0;
41
42
  /* Null-terminate the input for style_parse. */
43
3.55k
  buf = malloc(size + 1);
44
3.55k
  if (buf == NULL)
45
0
    return 0;
46
3.55k
  memcpy(buf, data, size);
47
3.55k
  buf[size] = '\0';
48
49
3.55k
  memset(&gc, 0, sizeof gc);
50
3.55k
  style_set(&sy, &gc);
51
52
3.55k
  style_parse(&sy, &gc, buf);
53
54
3.55k
  free(buf);
55
3.55k
  return 0;
56
3.55k
}
57
58
int
59
LLVMFuzzerInitialize(__unused int *argc, __unused char ***argv)
60
6
{
61
6
  const struct options_table_entry  *oe;
62
63
6
  global_environ = environ_create();
64
6
  global_options = options_create(NULL);
65
6
  global_s_options = options_create(NULL);
66
6
  global_w_options = options_create(NULL);
67
1.29k
  for (oe = options_table; oe->name != NULL; oe++) {
68
1.28k
    if (oe->scope & OPTIONS_TABLE_SERVER)
69
150
      options_default(global_options, oe);
70
1.28k
    if (oe->scope & OPTIONS_TABLE_SESSION)
71
666
      options_default(global_s_options, oe);
72
1.28k
    if (oe->scope & OPTIONS_TABLE_WINDOW)
73
468
      options_default(global_w_options, oe);
74
1.28k
  }
75
6
  libevent = osdep_event_init();
76
6
  socket_path = xstrdup("dummy");
77
78
6
  return 0;
79
6
}