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