blob: f2bd21b66b579a93de174167028d24e6e9735e6f [file] [log] [blame]
David Benjamin33b56922022-12-31 17:16:53 -05001/* Copyright (c) 2022, 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/conf.h>
17#include <openssl/x509.h>
David Benjamin33b56922022-12-31 17:16:53 -050018
David Benjaminb92fcfd2023-05-11 18:53:05 -040019#include <algorithm>
20
David Benjamin33b56922022-12-31 17:16:53 -050021extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
David Benjaminb92fcfd2023-05-11 18:53:05 -040022 // The string-based extensions APIs routinely produce output quadratic in
23 // their input. Cap the input size to mitigate this. See also
24 // https://crbug.com/boringssl/611.
25 len = std::min(len, size_t{8 * 1024});
26
David Benjamin33b56922022-12-31 17:16:53 -050027 bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(buf, len));
28 bssl::UniquePtr<CONF> conf(NCONF_new(nullptr));
29 if (NCONF_load_bio(conf.get(), bio.get(), nullptr)) {
30 // Run with and without |X509V3_CTX| information.
31 bssl::UniquePtr<X509> cert(X509_new());
32 X509V3_CTX ctx;
33 X509V3_set_ctx(&ctx, /*subject=*/cert.get(), /*issuer=*/cert.get(), nullptr,
34 nullptr, 0);
35 X509V3_EXT_add_nconf(conf.get(), &ctx, "default", cert.get());
36
37 cert.reset(X509_new());
38 X509V3_EXT_add_nconf(conf.get(), nullptr, "default", cert.get());
39 }
40 return 0;
41}