Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 1 | #include <assert.h> |
| 2 | |
| 3 | #include <openssl/ssl.h> |
| 4 | |
| 5 | struct GlobalState { |
| 6 | GlobalState() : ctx(SSL_CTX_new(SSLv23_method())) {} |
| 7 | |
| 8 | ~GlobalState() { |
| 9 | SSL_CTX_free(ctx); |
| 10 | } |
| 11 | |
| 12 | SSL_CTX *const ctx; |
| 13 | }; |
| 14 | |
| 15 | static GlobalState g_state; |
| 16 | |
| 17 | extern "C" int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len) { |
| 18 | // This only fuzzes the initial flow from the server so far. |
| 19 | SSL *client = SSL_new(g_state.ctx); |
| 20 | BIO *in = BIO_new(BIO_s_mem()); |
| 21 | BIO *out = BIO_new(BIO_s_mem()); |
| 22 | SSL_set_bio(client, in, out); |
| 23 | SSL_set_connect_state(client); |
| 24 | |
| 25 | BIO_write(in, buf, len); |
| 26 | SSL_do_handshake(client); |
| 27 | SSL_free(client); |
| 28 | |
| 29 | return 0; |
| 30 | } |