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