1 /* Copyright (c) 2016, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15 #include <openssl/bio.h>
16 #include <openssl/err.h>
17 #include <openssl/mem.h>
18 #include <openssl/pem.h>
19
20
LLVMFuzzerTestOneInput(const uint8_t * buf,size_t len)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
22 char *name, *header;
23 uint8_t *pem_data;
24 long pem_len;
25
26 BIO *bio = BIO_new_mem_buf(buf, len);
27
28 if (PEM_read_bio(bio, &name, &header, &pem_data, &pem_len) == 1) {
29 OPENSSL_free(name);
30 OPENSSL_free(header);
31 OPENSSL_free(pem_data);
32 }
33
34 BIO_free(bio);
35
36 ERR_clear_error();
37 return 0;
38 }
39