1c7da899bSchristos /*
2*b0d17251Schristos * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
3c7da899bSchristos *
4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License");
5c7da899bSchristos * you may not use this file except in compliance with the License.
6c7da899bSchristos * You may obtain a copy of the License at
7c7da899bSchristos * https://www.openssl.org/source/license.html
8c7da899bSchristos * or in the file LICENSE in the source distribution.
9c7da899bSchristos */
10c7da899bSchristos
11c7da899bSchristos /*
12c7da899bSchristos * Fuzz the parser used for dumping ASN.1 using "openssl asn1parse".
13c7da899bSchristos */
14c7da899bSchristos
15c7da899bSchristos #include <stdio.h>
16c7da899bSchristos #include <openssl/asn1.h>
17c7da899bSchristos #include <openssl/x509.h>
18c7da899bSchristos #include <openssl/x509v3.h>
1913d40330Schristos #include <openssl/err.h>
20c7da899bSchristos #include "fuzzer.h"
21c7da899bSchristos
2213d40330Schristos static BIO *bio_out;
2313d40330Schristos
FuzzerInitialize(int * argc,char *** argv)2413d40330Schristos int FuzzerInitialize(int *argc, char ***argv)
2513d40330Schristos {
26*b0d17251Schristos bio_out = BIO_new(BIO_s_null()); /* output will be ignored */
27*b0d17251Schristos if (bio_out == NULL)
28*b0d17251Schristos return 0;
2913d40330Schristos OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
30*b0d17251Schristos ERR_clear_error();
3113d40330Schristos CRYPTO_free_ex_index(0, -1);
32c7da899bSchristos return 1;
33c7da899bSchristos }
34c7da899bSchristos
FuzzerTestOneInput(const uint8_t * buf,size_t len)3513d40330Schristos int FuzzerTestOneInput(const uint8_t *buf, size_t len)
3613d40330Schristos {
37c7da899bSchristos (void)ASN1_parse_dump(bio_out, buf, len, 0, 0);
3813d40330Schristos ERR_clear_error();
39c7da899bSchristos return 0;
40c7da899bSchristos }
4113d40330Schristos
FuzzerCleanup(void)4213d40330Schristos void FuzzerCleanup(void)
4313d40330Schristos {
4413d40330Schristos BIO_free(bio_out);
4513d40330Schristos }
46