11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"); 51cb0ef41Sopenharmony_ci * you may not use this file except in compliance with the License. 61cb0ef41Sopenharmony_ci * You may obtain a copy of the License at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci * or in the file LICENSE in the source distribution. 91cb0ef41Sopenharmony_ci */ 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci/* 121cb0ef41Sopenharmony_ci * Fuzz the parser used for dumping ASN.1 using "openssl asn1parse". 131cb0ef41Sopenharmony_ci */ 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci#include <stdio.h> 161cb0ef41Sopenharmony_ci#include <openssl/asn1.h> 171cb0ef41Sopenharmony_ci#include <openssl/x509.h> 181cb0ef41Sopenharmony_ci#include <openssl/x509v3.h> 191cb0ef41Sopenharmony_ci#include <openssl/err.h> 201cb0ef41Sopenharmony_ci#include "fuzzer.h" 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cistatic BIO *bio_out; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciint FuzzerInitialize(int *argc, char ***argv) 251cb0ef41Sopenharmony_ci{ 261cb0ef41Sopenharmony_ci bio_out = BIO_new(BIO_s_null()); /* output will be ignored */ 271cb0ef41Sopenharmony_ci if (bio_out == NULL) 281cb0ef41Sopenharmony_ci return 0; 291cb0ef41Sopenharmony_ci OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); 301cb0ef41Sopenharmony_ci ERR_clear_error(); 311cb0ef41Sopenharmony_ci CRYPTO_free_ex_index(0, -1); 321cb0ef41Sopenharmony_ci return 1; 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciint FuzzerTestOneInput(const uint8_t *buf, size_t len) 361cb0ef41Sopenharmony_ci{ 371cb0ef41Sopenharmony_ci (void)ASN1_parse_dump(bio_out, buf, len, 0, 0); 381cb0ef41Sopenharmony_ci ERR_clear_error(); 391cb0ef41Sopenharmony_ci return 0; 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_civoid FuzzerCleanup(void) 431cb0ef41Sopenharmony_ci{ 441cb0ef41Sopenharmony_ci BIO_free(bio_out); 451cb0ef41Sopenharmony_ci} 46