xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/fuzz/asn1parse.c (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos /*
2*4724848cSchristos  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3*4724848cSchristos  *
4*4724848cSchristos  * Licensed under the OpenSSL licenses, (the "License");
5*4724848cSchristos  * you may not use this file except in compliance with the License.
6*4724848cSchristos  * You may obtain a copy of the License at
7*4724848cSchristos  * https://www.openssl.org/source/license.html
8*4724848cSchristos  * or in the file LICENSE in the source distribution.
9*4724848cSchristos  */
10*4724848cSchristos 
11*4724848cSchristos /*
12*4724848cSchristos  * Fuzz the parser used for dumping ASN.1 using "openssl asn1parse".
13*4724848cSchristos  */
14*4724848cSchristos 
15*4724848cSchristos #include <stdio.h>
16*4724848cSchristos #include <openssl/asn1.h>
17*4724848cSchristos #include <openssl/x509.h>
18*4724848cSchristos #include <openssl/x509v3.h>
19*4724848cSchristos #include <openssl/err.h>
20*4724848cSchristos #include "fuzzer.h"
21*4724848cSchristos 
22*4724848cSchristos static BIO *bio_out;
23*4724848cSchristos 
FuzzerInitialize(int * argc,char *** argv)24*4724848cSchristos int FuzzerInitialize(int *argc, char ***argv)
25*4724848cSchristos {
26*4724848cSchristos     bio_out = BIO_new_file("/dev/null", "w");
27*4724848cSchristos     OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
28*4724848cSchristos     ERR_get_state();
29*4724848cSchristos     CRYPTO_free_ex_index(0, -1);
30*4724848cSchristos     return 1;
31*4724848cSchristos }
32*4724848cSchristos 
FuzzerTestOneInput(const uint8_t * buf,size_t len)33*4724848cSchristos int FuzzerTestOneInput(const uint8_t *buf, size_t len)
34*4724848cSchristos {
35*4724848cSchristos     (void)ASN1_parse_dump(bio_out, buf, len, 0, 0);
36*4724848cSchristos     ERR_clear_error();
37*4724848cSchristos     return 0;
38*4724848cSchristos }
39*4724848cSchristos 
FuzzerCleanup(void)40*4724848cSchristos void FuzzerCleanup(void)
41*4724848cSchristos {
42*4724848cSchristos     BIO_free(bio_out);
43*4724848cSchristos }
44