fuzzterm.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include "putty.h"
  5. #include "dialog.h"
  6. #include "terminal.h"
  7. static const TermWinVtable fuzz_termwin_vt;
  8. int main(int argc, char **argv)
  9. {
  10. char blk[512];
  11. size_t len;
  12. Terminal *term;
  13. Conf *conf;
  14. struct unicode_data ucsdata;
  15. TermWin termwin;
  16. termwin.vt = &fuzz_termwin_vt;
  17. conf = conf_new();
  18. do_defaults(NULL, conf);
  19. init_ucs_generic(conf, &ucsdata);
  20. term = term_init(conf, &ucsdata, &termwin);
  21. term_size(term, 24, 80, 10000);
  22. term->ldisc = NULL;
  23. /* Tell american fuzzy lop that this is a good place to fork. */
  24. #ifdef __AFL_HAVE_MANUAL_CONTROL
  25. __AFL_INIT();
  26. #endif
  27. while (!feof(stdin)) {
  28. len = fread(blk, 1, sizeof(blk), stdin);
  29. term_data(term, blk, len);
  30. }
  31. term_update(term);
  32. return 0;
  33. }
  34. /* functions required by terminal.c */
  35. static bool fuzz_setup_draw_ctx(TermWin *tw) { return true; }
  36. static void fuzz_draw_text(
  37. TermWin *tw, int x, int y, wchar_t *text, int len,
  38. unsigned long attr, int lattr, truecolour tc)
  39. {
  40. int i;
  41. printf("TEXT[attr=%08lx,lattr=%02x]@(%d,%d):", attr, lattr, x, y);
  42. for (i = 0; i < len; i++) {
  43. printf(" %x", (unsigned)text[i]);
  44. }
  45. printf("\n");
  46. }
  47. static void fuzz_draw_cursor(
  48. TermWin *tw, int x, int y, wchar_t *text, int len,
  49. unsigned long attr, int lattr, truecolour tc)
  50. {
  51. int i;
  52. printf("CURS[attr=%08lx,lattr=%02x]@(%d,%d):", attr, lattr, x, y);
  53. for (i = 0; i < len; i++) {
  54. printf(" %x", (unsigned)text[i]);
  55. }
  56. printf("\n");
  57. }
  58. static void fuzz_draw_trust_sigil(TermWin *tw, int x, int y)
  59. {
  60. printf("TRUST@(%d,%d)\n", x, y);
  61. }
  62. static int fuzz_char_width(TermWin *tw, int uc) { return 1; }
  63. static void fuzz_free_draw_ctx(TermWin *tw) {}
  64. static void fuzz_set_cursor_pos(TermWin *tw, int x, int y) {}
  65. static void fuzz_set_raw_mouse_mode(TermWin *tw, bool enable) {}
  66. static void fuzz_set_scrollbar(TermWin *tw, int total, int start, int page) {}
  67. static void fuzz_bell(TermWin *tw, int mode) {}
  68. static void fuzz_clip_write(
  69. TermWin *tw, int clipboard, wchar_t *text, int *attrs,
  70. truecolour *colours, int len, bool must_deselect) {}
  71. static void fuzz_clip_request_paste(TermWin *tw, int clipboard) {}
  72. static void fuzz_refresh(TermWin *tw) {}
  73. static void fuzz_request_resize(TermWin *tw, int w, int h) {}
  74. static void fuzz_set_title(TermWin *tw, const char *title, int codepage) {}
  75. static void fuzz_set_icon_title(TermWin *tw, const char *icontitle, int cp) {}
  76. static void fuzz_set_minimised(TermWin *tw, bool minimised) {}
  77. static void fuzz_set_maximised(TermWin *tw, bool maximised) {}
  78. static void fuzz_move(TermWin *tw, int x, int y) {}
  79. static void fuzz_set_zorder(TermWin *tw, bool top) {}
  80. static void fuzz_palette_set(TermWin *tw, unsigned start, unsigned ncolours,
  81. const rgb *colours) {}
  82. static void fuzz_palette_get_overrides(TermWin *tw, Terminal *term) {}
  83. static void fuzz_unthrottle(TermWin *tw, size_t size) {}
  84. static const TermWinVtable fuzz_termwin_vt = {
  85. .setup_draw_ctx = fuzz_setup_draw_ctx,
  86. .draw_text = fuzz_draw_text,
  87. .draw_cursor = fuzz_draw_cursor,
  88. .draw_trust_sigil = fuzz_draw_trust_sigil,
  89. .char_width = fuzz_char_width,
  90. .free_draw_ctx = fuzz_free_draw_ctx,
  91. .set_cursor_pos = fuzz_set_cursor_pos,
  92. .set_raw_mouse_mode = fuzz_set_raw_mouse_mode,
  93. .set_scrollbar = fuzz_set_scrollbar,
  94. .bell = fuzz_bell,
  95. .clip_write = fuzz_clip_write,
  96. .clip_request_paste = fuzz_clip_request_paste,
  97. .refresh = fuzz_refresh,
  98. .request_resize = fuzz_request_resize,
  99. .set_title = fuzz_set_title,
  100. .set_icon_title = fuzz_set_icon_title,
  101. .set_minimised = fuzz_set_minimised,
  102. .set_maximised = fuzz_set_maximised,
  103. .move = fuzz_move,
  104. .set_zorder = fuzz_set_zorder,
  105. .palette_set = fuzz_palette_set,
  106. .palette_get_overrides = fuzz_palette_get_overrides,
  107. .unthrottle = fuzz_unthrottle,
  108. };
  109. void ldisc_send(Ldisc *ldisc, const void *buf, int len, bool interactive) {}
  110. void ldisc_echoedit_update(Ldisc *ldisc) {}
  111. void ldisc_provide_userpass_le(Ldisc *ldisc, TermLineEditor *le)
  112. { unreachable("This fake ldisc should never be used for user/pass prompts"); }
  113. void modalfatalbox(const char *fmt, ...) { exit(0); }
  114. void nonfatal(const char *fmt, ...) { }
  115. /* needed by timing.c */
  116. void timer_change_notify(unsigned long next) { }
  117. /* needed by config.c */
  118. void dlg_radiobutton_set(dlgcontrol *ctrl, dlgparam *dp, int whichbutton) { }
  119. int dlg_radiobutton_get(dlgcontrol *ctrl, dlgparam *dp) { return 0; }
  120. void dlg_checkbox_set(dlgcontrol *ctrl, dlgparam *dp, bool checked) { }
  121. bool dlg_checkbox_get(dlgcontrol *ctrl, dlgparam *dp) { return false; }
  122. void dlg_editbox_set(dlgcontrol *ctrl, dlgparam *dp, char const *text) { }
  123. char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp)
  124. { return dupstr("moo"); }
  125. void dlg_listbox_clear(dlgcontrol *ctrl, dlgparam *dp) { }
  126. void dlg_listbox_del(dlgcontrol *ctrl, dlgparam *dp, int index) { }
  127. void dlg_listbox_add(dlgcontrol *ctrl, dlgparam *dp, char const *text) { }
  128. void dlg_listbox_addwithid(dlgcontrol *ctrl, dlgparam *dp,
  129. char const *text, int id) { }
  130. int dlg_listbox_getid(dlgcontrol *ctrl, dlgparam *dp, int index)
  131. { return 0; }
  132. int dlg_listbox_index(dlgcontrol *ctrl, dlgparam *dp) { return -1; }
  133. bool dlg_listbox_issel(dlgcontrol *ctrl, dlgparam *dp, int index)
  134. { return false; }
  135. void dlg_listbox_select(dlgcontrol *ctrl, dlgparam *dp, int index) { }
  136. void dlg_text_set(dlgcontrol *ctrl, dlgparam *dp, char const *text) { }
  137. void dlg_filesel_set(dlgcontrol *ctrl, dlgparam *dp, Filename *fn) { }
  138. Filename *dlg_filesel_get(dlgcontrol *ctrl, dlgparam *dp) { return NULL; }
  139. void dlg_fontsel_set(dlgcontrol *ctrl, dlgparam *dp, FontSpec *fn) { }
  140. FontSpec *dlg_fontsel_get(dlgcontrol *ctrl, dlgparam *dp) { return NULL; }
  141. void dlg_update_start(dlgcontrol *ctrl, dlgparam *dp) { }
  142. void dlg_update_done(dlgcontrol *ctrl, dlgparam *dp) { }
  143. void dlg_set_focus(dlgcontrol *ctrl, dlgparam *dp) { }
  144. void dlg_label_change(dlgcontrol *ctrl, dlgparam *dp, char const *text) { }
  145. dlgcontrol *dlg_last_focused(dlgcontrol *ctrl, dlgparam *dp)
  146. { return NULL; }
  147. void dlg_beep(dlgparam *dp) { }
  148. void dlg_error_msg(dlgparam *dp, const char *msg) { }
  149. void dlg_end(dlgparam *dp, int value) { }
  150. void dlg_coloursel_start(dlgcontrol *ctrl, dlgparam *dp,
  151. int r, int g, int b) { }
  152. bool dlg_coloursel_results(dlgcontrol *ctrl, dlgparam *dp,
  153. int *r, int *g, int *b) { return false; }
  154. void dlg_refresh(dlgcontrol *ctrl, dlgparam *dp) { }
  155. bool dlg_is_visible(dlgcontrol *ctrl, dlgparam *dp) { return false; }
  156. const int ngsslibs = 0;
  157. const char *const gsslibnames[0] = { };
  158. const struct keyvalwhere gsslibkeywords[0] = { };
  159. /*
  160. * Default settings that are specific to Unix plink.
  161. */
  162. char *platform_default_s(const char *name)
  163. {
  164. if (!strcmp(name, "TermType"))
  165. return dupstr(getenv("TERM"));
  166. if (!strcmp(name, "SerialLine"))
  167. return dupstr("/dev/ttyS0");
  168. return NULL;
  169. }
  170. bool platform_default_b(const char *name, bool def)
  171. {
  172. return def;
  173. }
  174. int platform_default_i(const char *name, int def)
  175. {
  176. return def;
  177. }
  178. FontSpec *platform_default_fontspec(const char *name)
  179. {
  180. return fontspec_new_default();
  181. }
  182. Filename *platform_default_filename(const char *name)
  183. {
  184. if (!strcmp(name, "LogFileName"))
  185. return filename_from_str("putty.log");
  186. else
  187. return filename_from_str("");
  188. }
  189. char *x_get_default(const char *key)
  190. {
  191. return NULL; /* this is a stub */
  192. }