xref: /freebsd/crypto/openssl/fuzz/crl.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  *
4*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License");
5*e0c4386eSCy Schubert  * you may not use this file except in compliance with the License.
6*e0c4386eSCy Schubert  * You may obtain a copy of the License at
7*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert  * or in the file LICENSE in the source distribution.
9*e0c4386eSCy Schubert  */
10*e0c4386eSCy Schubert 
11*e0c4386eSCy Schubert #include <openssl/x509.h>
12*e0c4386eSCy Schubert #include <openssl/bio.h>
13*e0c4386eSCy Schubert #include <openssl/err.h>
14*e0c4386eSCy Schubert #include "fuzzer.h"
15*e0c4386eSCy Schubert 
FuzzerInitialize(int * argc,char *** argv)16*e0c4386eSCy Schubert int FuzzerInitialize(int *argc, char ***argv)
17*e0c4386eSCy Schubert {
18*e0c4386eSCy Schubert     OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
19*e0c4386eSCy Schubert     ERR_clear_error();
20*e0c4386eSCy Schubert     CRYPTO_free_ex_index(0, -1);
21*e0c4386eSCy Schubert     return 1;
22*e0c4386eSCy Schubert }
23*e0c4386eSCy Schubert 
FuzzerTestOneInput(const uint8_t * buf,size_t len)24*e0c4386eSCy Schubert int FuzzerTestOneInput(const uint8_t *buf, size_t len)
25*e0c4386eSCy Schubert {
26*e0c4386eSCy Schubert     const unsigned char *p = buf;
27*e0c4386eSCy Schubert     unsigned char *der = NULL;
28*e0c4386eSCy Schubert 
29*e0c4386eSCy Schubert     X509_CRL *crl = d2i_X509_CRL(NULL, &p, len);
30*e0c4386eSCy Schubert     if (crl != NULL) {
31*e0c4386eSCy Schubert         BIO *bio = BIO_new(BIO_s_null());
32*e0c4386eSCy Schubert         X509_CRL_print(bio, crl);
33*e0c4386eSCy Schubert         BIO_free(bio);
34*e0c4386eSCy Schubert 
35*e0c4386eSCy Schubert         i2d_X509_CRL(crl, &der);
36*e0c4386eSCy Schubert         OPENSSL_free(der);
37*e0c4386eSCy Schubert 
38*e0c4386eSCy Schubert         X509_CRL_free(crl);
39*e0c4386eSCy Schubert     }
40*e0c4386eSCy Schubert     ERR_clear_error();
41*e0c4386eSCy Schubert 
42*e0c4386eSCy Schubert     return 0;
43*e0c4386eSCy Schubert }
44*e0c4386eSCy Schubert 
FuzzerCleanup(void)45*e0c4386eSCy Schubert void FuzzerCleanup(void)
46*e0c4386eSCy Schubert {
47*e0c4386eSCy Schubert }
48