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