// Entry point for LibFuzzer. int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { struct tsm_screen *screen; struct tsm_vte *vte; const int scrollback_size = 200; // frecon use 200 tsm_screen_new(&screen, NULL, NULL); tsm_screen_set_max_sb(screen, scrollback_size); tsm_vte_new(&vte, screen, terminal_write_fn, NULL, NULL, NULL); tsm_screen_resize(screen, WIDTH, HEIGHT); tsm_vte_input(vte, (const char*) data, size); tsm_screen_draw(screen, term_draw_cell, NULL); tsm_vte_unref(vte); tsm_screen_unref(screen); return 0; }
int main(int argc, char** argv) { const char* val; if (tsm_screen_new(&term.screen, tsm_log, 0) < 0){ printf("fatal, couldn't setup tsm screen\n"); return EXIT_FAILURE; } if (tsm_vte_new(&term.vte, term.screen, write_callback, NULL /* write_cb_data */, tsm_log, NULL /* tsm_log_data */) < 0){ printf("fatal, couldn't setup vte\n"); return EXIT_FAILURE; } tsm_screen_set_max_sb(term.screen, 1000); setlocale(LC_CTYPE, "C"); signal(SIGHUP, SIG_IGN); if ( (term.child = shl_pty_open(&term.pty, read_callback, NULL, 10, 5)) == 0){ setup_shell(); exit(EXIT_FAILURE); } if (term.child < 0){ printf("couldn't spawn child terminal.\n"); return EXIT_FAILURE; } short pollev = POLLIN | POLLERR | POLLNVAL | POLLHUP; int ptyfd = shl_pty_get_fd(term.pty); int age = 0; tsm_screen_resize(term.screen, 10, 5); shl_pty_resize(term.pty, 10, 5); while(1){ int pc = 2; struct pollfd fds[3] = { { .fd = ptyfd, .events = pollev}, { .fd = STDIN_FILENO, .events = pollev} };
END_TEST START_TEST(test_screen_null) { int r; unsigned int n; r = tsm_screen_new(NULL, NULL, NULL); ck_assert_int_eq(r, -EINVAL); tsm_screen_ref(NULL); tsm_screen_unref(NULL); tsm_screen_set_opts(NULL, 0u); tsm_screen_reset_opts(NULL, 0u); n = tsm_screen_get_opts(NULL); ck_assert_int_eq(n, 0); n = tsm_screen_get_width(NULL); ck_assert_int_eq(n, 0); n = tsm_screen_get_height(NULL); ck_assert_int_eq(n, 0); r = tsm_screen_resize(NULL, 0, 0); ck_assert_int_eq(r, -EINVAL); r = tsm_screen_set_margins(NULL, 0u, 0u); ck_assert_int_eq(r, -EINVAL); tsm_screen_set_max_sb(NULL, 0u); tsm_screen_clear_sb(NULL); tsm_screen_sb_up(NULL, 0u); tsm_screen_sb_down(NULL, 0u); tsm_screen_sb_page_up(NULL, 0u); tsm_screen_sb_page_down(NULL, 0u); tsm_screen_sb_reset(NULL); tsm_screen_set_def_attr(NULL, NULL); tsm_screen_reset(NULL); tsm_screen_set_flags(NULL, 0u); tsm_screen_reset_flags(NULL, 0u); n = tsm_screen_get_flags(NULL); ck_assert_int_eq(n, 0); n = tsm_screen_get_cursor_x(NULL); ck_assert_int_eq(n, 0); n = tsm_screen_get_cursor_y(NULL); ck_assert_int_eq(n, 0); tsm_screen_set_tabstop(NULL); tsm_screen_reset_tabstop(NULL); tsm_screen_reset_all_tabstops(NULL); tsm_screen_write(NULL, 0u, NULL); tsm_screen_newline(NULL); tsm_screen_scroll_up(NULL, 0u); tsm_screen_scroll_down(NULL, 0u); tsm_screen_move_to(NULL, 0u, 0u); tsm_screen_move_up(NULL, 0u, false); tsm_screen_move_down(NULL, 0u, false); tsm_screen_move_right(NULL, 0u); tsm_screen_move_left(NULL, 0u); tsm_screen_move_line_end(NULL); tsm_screen_move_line_home(NULL); tsm_screen_tab_right(NULL, 0u); tsm_screen_tab_left(NULL, 0u); tsm_screen_insert_lines(NULL, 0u); tsm_screen_delete_lines(NULL, 0u); tsm_screen_insert_chars(NULL, 0u); tsm_screen_delete_chars(NULL, 0u); tsm_screen_erase_cursor(NULL); tsm_screen_erase_chars(NULL, 0u); tsm_screen_erase_cursor_to_end(NULL, false); tsm_screen_erase_home_to_cursor(NULL, false); tsm_screen_erase_current_line(NULL, false); tsm_screen_erase_screen_to_cursor(NULL, false); tsm_screen_erase_cursor_to_screen(NULL, false); tsm_screen_erase_screen(NULL, false); }