]> git.ipfire.org Git - thirdparty/openssl.git/blame - fuzz/cms.c
Fix race for X509 store found by thread sanitizer
[thirdparty/openssl.git] / fuzz / cms.c
CommitLineData
c38bb727
BL
1/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
0642931f 4 * Licensed under the Apache License 2.0 (the "License");
c38bb727
BL
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
9 */
10
11/*
12 * Test CMS DER parsing.
13 */
14
15#include <openssl/bio.h>
16#include <openssl/cms.h>
d69d8f90 17#include <openssl/err.h>
c38bb727
BL
18#include "fuzzer.h"
19
f3e911d5
KR
20int FuzzerInitialize(int *argc, char ***argv)
21{
d69d8f90 22 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
e5d4233f 23 ERR_clear_error();
d69d8f90 24 CRYPTO_free_ex_index(0, -1);
90d28f05
BL
25 return 1;
26}
27
f3e911d5
KR
28int FuzzerTestOneInput(const uint8_t *buf, size_t len)
29{
1b6a77a1 30 CMS_ContentInfo *cms;
ba740700 31 BIO *in;
1b6a77a1
KR
32
33 if (len == 0)
ba740700 34 return 0;
90d28f05 35
ba740700 36 in = BIO_new(BIO_s_mem());
c38bb727 37 OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
1b6a77a1
KR
38 cms = d2i_CMS_bio(in, NULL);
39 if (cms != NULL) {
40 BIO *out = BIO_new(BIO_s_null());
41
42 i2d_CMS_bio(out, cms);
43 BIO_free(out);
44 CMS_ContentInfo_free(cms);
45 }
46
c38bb727 47 BIO_free(in);
d69d8f90 48 ERR_clear_error();
1b6a77a1 49
c38bb727
BL
50 return 0;
51}
ad4da7fb
KR
52
53void FuzzerCleanup(void)
54{
55}