tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

input-fuzzer.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Sergey Nizovtsev <snizovtsev@gmail.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 #include <stddef.h>
18 #include <assert.h>
19 
20 #include "tmux.h"
21 
22 #define FUZZER_MAXLEN 512
23 #define PANE_WIDTH 80
24 #define PANE_HEIGHT 25
25 
26 struct event_base *libevent;
27 
28 int
29 LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
30 {
31  struct bufferevent *vpty[2];
32  struct window *w;
33  struct window_pane *wp;
34  int error;
35 
36  /*
37  * Since AFL doesn't support -max_len paramenter we have to
38  * discard long inputs manually.
39  */
40  if (size > FUZZER_MAXLEN)
41  return 0;
42 
44  wp = window_add_pane(w, NULL, 0, 0);
45  bufferevent_pair_new(libevent, BEV_OPT_CLOSE_ON_FREE, vpty);
46  wp->ictx = input_init(wp, vpty[0]);
47  window_add_ref(w, __func__);
48 
49  input_parse_buffer(wp, (u_char*) data, size);
50  while (cmdq_next(NULL) != 0)
51  ;
52  error = event_base_loop(libevent, EVLOOP_NONBLOCK);
53  if (error == -1)
54  errx(1, "event_base_loop failed");
55 
56  assert(w->references == 1);
57  window_remove_ref(w, __func__);
58 
59  bufferevent_free(vpty[0]);
60  bufferevent_free(vpty[1]);
61 
62  return 0;
63 }
64 
65 int
67 {
68  const struct options_table_entry *oe;
69 
74  for (oe = options_table; oe->name != NULL; oe++) {
75  if (oe->scope & OPTIONS_TABLE_SERVER)
77  if (oe->scope & OPTIONS_TABLE_SESSION)
79  if (oe->scope & OPTIONS_TABLE_WINDOW)
81  }
83 
84  options_set_number(global_w_options, "monitor-bell", 0);
85  options_set_number(global_w_options, "allow-rename", 1);
86  options_set_number(global_options, "set-clipboard", 2);
87 
88  return 0;
89 }
u_int cmdq_next(struct client *c)
Definition: cmd-queue.c:685
#define __unused
Definition: compat.h:60
void errx(int, const char *,...)
struct environ * environ_create(void)
Definition: environ.c:44
struct event_base * libevent
Definition: input-fuzzer.c:26
#define PANE_HEIGHT
Definition: input-fuzzer.c:24
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
Definition: input-fuzzer.c:29
#define PANE_WIDTH
Definition: input-fuzzer.c:23
int LLVMFuzzerInitialize(int *argc, char ***argv)
Definition: input-fuzzer.c:66
#define FUZZER_MAXLEN
Definition: input-fuzzer.c:22
void input_parse_buffer(struct window_pane *wp, u_char *buf, size_t len)
Definition: input.c:957
struct input_ctx * input_init(struct window_pane *wp, struct bufferevent *bev)
Definition: input.c:800
const struct options_table_entry options_table[]
struct options_entry * options_default(struct options *oo, const struct options_table_entry *oe)
Definition: options.c:258
struct options * options_create(struct options *parent)
Definition: options.c:171
struct options_entry * options_set_number(struct options *oo, const char *name, long long value)
Definition: options.c:752
struct event_base * osdep_event_init(void)
Definition: osdep-aix.c:92
Definition: tmux.h:1830
const char * name
Definition: tmux.h:1831
int scope
Definition: tmux.h:1834
int argc
Definition: tmux.h:992
char ** argv
Definition: tmux.h:993
struct input_ctx * ictx
Definition: tmux.h:1010
Definition: tmux.h:1041
u_int references
Definition: tmux.h:1087
struct environ * global_environ
Definition: tmux.c:39
struct options * global_s_options
Definition: tmux.c:37
struct options * global_w_options
Definition: tmux.c:38
struct options * global_options
Definition: tmux.c:36
void window_remove_ref(struct window *, const char *)
Definition: window.c:391
struct window_pane * window_add_pane(struct window *, struct window_pane *, u_int, int)
Definition: window.c:656
#define OPTIONS_TABLE_WINDOW
Definition: tmux.h:1823
#define OPTIONS_TABLE_SESSION
Definition: tmux.h:1822
void window_add_ref(struct window *, const char *)
Definition: window.c:384
#define OPTIONS_TABLE_SERVER
Definition: tmux.h:1821
struct window * window_create(u_int, u_int, u_int, u_int)
Definition: window.c:298