2 * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
11 #include <openssl/pem.h>
12 #include <openssl/err.h>
15 int FuzzerInitialize(int *argc
, char ***argv
)
17 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS
, NULL
);
19 CRYPTO_free_ex_index(0, -1);
23 int FuzzerTestOneInput(const uint8_t *buf
, size_t len
)
26 char *name
= NULL
, *header
= NULL
;
27 unsigned char *data
= NULL
;
33 in
= BIO_new(BIO_s_mem());
34 OPENSSL_assert((size_t)BIO_write(in
, buf
+ 1, len
- 1) == len
- 1);
35 if (PEM_read_bio_ex(in
, &name
, &header
, &data
, &outlen
, buf
[0]) == 1) {
36 /* Try to read all the data we get to see if allocated properly. */
37 BIO_write(in
, name
, strlen(name
));
38 BIO_write(in
, header
, strlen(header
));
39 BIO_write(in
, data
, outlen
);
41 if (buf
[0] & PEM_FLAG_SECURE
) {
42 OPENSSL_secure_free(name
);
43 OPENSSL_secure_free(header
);
44 OPENSSL_secure_free(data
);
57 void FuzzerCleanup(void)