25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
862 B

  1. #include <assert.h>
  2. #include <openssl/rand.h>
  3. #include <openssl/ssl.h>
  4. struct GlobalState {
  5. GlobalState() : ctx(SSL_CTX_new(SSLv23_method())) {}
  6. ~GlobalState() {
  7. SSL_CTX_free(ctx);
  8. }
  9. SSL_CTX *const ctx;
  10. };
  11. static GlobalState g_state;
  12. extern "C" int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len) {
  13. RAND_reset_for_fuzzing();
  14. SSL *client = SSL_new(g_state.ctx);
  15. BIO *in = BIO_new(BIO_s_mem());
  16. BIO *out = BIO_new(BIO_s_mem());
  17. SSL_set_bio(client, in, out);
  18. SSL_set_connect_state(client);
  19. SSL_set_renegotiate_mode(client, ssl_renegotiate_freely);
  20. BIO_write(in, buf, len);
  21. if (SSL_do_handshake(client) == 1) {
  22. // Keep reading application data until error or EOF.
  23. uint8_t tmp[1024];
  24. for (;;) {
  25. if (SSL_read(client, tmp, sizeof(tmp)) <= 0) {
  26. break;
  27. }
  28. }
  29. }
  30. SSL_free(client);
  31. return 0;
  32. }