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 /*
12*e0c4386eSCy Schubert * Test CMS DER parsing.
13*e0c4386eSCy Schubert */
14*e0c4386eSCy Schubert
15*e0c4386eSCy Schubert #include <openssl/bio.h>
16*e0c4386eSCy Schubert #include <openssl/cms.h>
17*e0c4386eSCy Schubert #include <openssl/err.h>
18*e0c4386eSCy Schubert #include "fuzzer.h"
19*e0c4386eSCy Schubert
FuzzerInitialize(int * argc,char *** argv)20*e0c4386eSCy Schubert int FuzzerInitialize(int *argc, char ***argv)
21*e0c4386eSCy Schubert {
22*e0c4386eSCy Schubert OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
23*e0c4386eSCy Schubert ERR_clear_error();
24*e0c4386eSCy Schubert CRYPTO_free_ex_index(0, -1);
25*e0c4386eSCy Schubert return 1;
26*e0c4386eSCy Schubert }
27*e0c4386eSCy Schubert
FuzzerTestOneInput(const uint8_t * buf,size_t len)28*e0c4386eSCy Schubert int FuzzerTestOneInput(const uint8_t *buf, size_t len)
29*e0c4386eSCy Schubert {
30*e0c4386eSCy Schubert CMS_ContentInfo *cms;
31*e0c4386eSCy Schubert BIO *in;
32*e0c4386eSCy Schubert
33*e0c4386eSCy Schubert if (len == 0)
34*e0c4386eSCy Schubert return 0;
35*e0c4386eSCy Schubert
36*e0c4386eSCy Schubert in = BIO_new(BIO_s_mem());
37*e0c4386eSCy Schubert OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
38*e0c4386eSCy Schubert cms = d2i_CMS_bio(in, NULL);
39*e0c4386eSCy Schubert if (cms != NULL) {
40*e0c4386eSCy Schubert BIO *out = BIO_new(BIO_s_null());
41*e0c4386eSCy Schubert
42*e0c4386eSCy Schubert i2d_CMS_bio(out, cms);
43*e0c4386eSCy Schubert BIO_free(out);
44*e0c4386eSCy Schubert CMS_ContentInfo_free(cms);
45*e0c4386eSCy Schubert }
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubert BIO_free(in);
48*e0c4386eSCy Schubert ERR_clear_error();
49*e0c4386eSCy Schubert
50*e0c4386eSCy Schubert return 0;
51*e0c4386eSCy Schubert }
52*e0c4386eSCy Schubert
FuzzerCleanup(void)53*e0c4386eSCy Schubert void FuzzerCleanup(void)
54*e0c4386eSCy Schubert {
55*e0c4386eSCy Schubert }
56