xref: /freebsd-src/crypto/openssl/fuzz/ct.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  *
4*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License");
5*e0c4386eSCy Schubert  * you may not use this file except in compliance with the License.
6*e0c4386eSCy Schubert  * You may obtain a copy of the License at
7*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert  * or in the file LICENSE in the source distribution.
9*e0c4386eSCy Schubert  */
10*e0c4386eSCy Schubert 
11*e0c4386eSCy Schubert /*
12*e0c4386eSCy Schubert  * Fuzz the SCT parser.
13*e0c4386eSCy Schubert  */
14*e0c4386eSCy Schubert 
15*e0c4386eSCy Schubert #include <stdio.h>
16*e0c4386eSCy Schubert #include <openssl/ct.h>
17*e0c4386eSCy Schubert #include <openssl/err.h>
18*e0c4386eSCy Schubert #include "fuzzer.h"
19*e0c4386eSCy Schubert 
FuzzerInitialize(int * argc,char *** argv)20*e0c4386eSCy Schubert int FuzzerInitialize(int *argc, char ***argv)
21*e0c4386eSCy Schubert {
22*e0c4386eSCy Schubert     OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
23*e0c4386eSCy Schubert     CRYPTO_free_ex_index(0, -1);
24*e0c4386eSCy Schubert     ERR_clear_error();
25*e0c4386eSCy Schubert     return 1;
26*e0c4386eSCy Schubert }
27*e0c4386eSCy Schubert 
FuzzerTestOneInput(const uint8_t * buf,size_t len)28*e0c4386eSCy Schubert int FuzzerTestOneInput(const uint8_t *buf, size_t len)
29*e0c4386eSCy Schubert {
30*e0c4386eSCy Schubert     const uint8_t **pp = &buf;
31*e0c4386eSCy Schubert     unsigned char *der = NULL;
32*e0c4386eSCy Schubert     STACK_OF(SCT) *scts = d2i_SCT_LIST(NULL, pp, len);
33*e0c4386eSCy Schubert     if (scts != NULL) {
34*e0c4386eSCy Schubert         BIO *bio = BIO_new(BIO_s_null());
35*e0c4386eSCy Schubert         SCT_LIST_print(scts, bio, 4, "\n", NULL);
36*e0c4386eSCy Schubert         BIO_free(bio);
37*e0c4386eSCy Schubert 
38*e0c4386eSCy Schubert         if (i2d_SCT_LIST(scts, &der)) {
39*e0c4386eSCy Schubert             /* Silence unused result warning */
40*e0c4386eSCy Schubert         }
41*e0c4386eSCy Schubert         OPENSSL_free(der);
42*e0c4386eSCy Schubert 
43*e0c4386eSCy Schubert         SCT_LIST_free(scts);
44*e0c4386eSCy Schubert     }
45*e0c4386eSCy Schubert     ERR_clear_error();
46*e0c4386eSCy Schubert     return 0;
47*e0c4386eSCy Schubert }
48*e0c4386eSCy Schubert 
FuzzerCleanup(void)49*e0c4386eSCy Schubert void FuzzerCleanup(void)
50*e0c4386eSCy Schubert {
51*e0c4386eSCy Schubert }
52