Home | History | Annotate | Line # | Download | only in fuzz
      1  1.1  christos /*
      2  1.1  christos  * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
      3  1.1  christos  *
      4  1.1  christos  * Licensed under the Apache License 2.0 (the "License");
      5  1.1  christos  * you may not use this file except in compliance with the License.
      6  1.1  christos  * You may obtain a copy of the License at
      7  1.1  christos  * https://www.openssl.org/source/license.html
      8  1.1  christos  * or in the file LICENSE in the source distribution.
      9  1.1  christos  */
     10  1.1  christos 
     11  1.1  christos /*
     12  1.1  christos  * Fuzz the parser used for dumping ASN.1 using "openssl asn1parse".
     13  1.1  christos  */
     14  1.1  christos 
     15  1.1  christos #include <stdio.h>
     16  1.1  christos #include <openssl/asn1.h>
     17  1.1  christos #include <openssl/x509.h>
     18  1.1  christos #include <openssl/x509v3.h>
     19  1.1  christos #include <openssl/err.h>
     20  1.1  christos #include "fuzzer.h"
     21  1.1  christos 
     22  1.1  christos static BIO *bio_out;
     23  1.1  christos 
     24  1.1  christos int FuzzerInitialize(int *argc, char ***argv)
     25  1.1  christos {
     26  1.1  christos     bio_out = BIO_new(BIO_s_null()); /* output will be ignored */
     27  1.1  christos     if (bio_out == NULL)
     28  1.1  christos         return 0;
     29  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
     30  1.1  christos     ERR_clear_error();
     31  1.1  christos     CRYPTO_free_ex_index(0, -1);
     32  1.1  christos     return 1;
     33  1.1  christos }
     34  1.1  christos 
     35  1.1  christos int FuzzerTestOneInput(const uint8_t *buf, size_t len)
     36  1.1  christos {
     37  1.1  christos     (void)ASN1_parse_dump(bio_out, buf, len, 0, 0);
     38  1.1  christos     ERR_clear_error();
     39  1.1  christos     return 0;
     40  1.1  christos }
     41  1.1  christos 
     42  1.1  christos void FuzzerCleanup(void)
     43  1.1  christos {
     44  1.1  christos     BIO_free(bio_out);
     45  1.1  christos }
     46