fuzzer-pubkey.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "fuzz.h"
  2. #include "session.h"
  3. #include "fuzz-wrapfd.h"
  4. #include "debug.h"
  5. static void setup_fuzzer(void) {
  6. fuzz_common_setup();
  7. }
  8. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  9. static int once = 0;
  10. if (!once) {
  11. setup_fuzzer();
  12. once = 1;
  13. }
  14. if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  15. return 0;
  16. }
  17. m_malloc_set_epoch(1);
  18. if (setjmp(fuzz.jmp) == 0) {
  19. buffer *line = buf_getstringbuf(fuzz.input);
  20. buffer *keyblob = buf_getstringbuf(fuzz.input);
  21. unsigned int algolen;
  22. char* algoname = buf_getstring(keyblob, &algolen);
  23. if (signature_type_from_name(algoname, algolen) == DROPBEAR_SIGNATURE_NONE) {
  24. dropbear_exit("fuzzer imagined a bogus algorithm");
  25. }
  26. int ret = fuzz_checkpubkey_line(line, 5, "/home/me/authorized_keys",
  27. algoname, algolen,
  28. keyblob->data, keyblob->len);
  29. if (ret == DROPBEAR_SUCCESS) {
  30. /* fuzz_checkpubkey_line() should have cleaned up for failure */
  31. svr_pubkey_options_cleanup();
  32. }
  33. buf_free(line);
  34. buf_free(keyblob);
  35. m_free(algoname);
  36. m_malloc_free_epoch(1, 0);
  37. } else {
  38. m_malloc_free_epoch(1, 1);
  39. TRACE(("dropbear_exit longjmped"))
  40. /* dropbear_exit jumped here */
  41. }
  42. return 0;
  43. }