blob: 72dd798711baa09c3adff95e3a4b24e4d3c677be [file] [log] [blame]
Ben Laurie4a2c4c12016-06-03 11:07:42 +01001/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL licenses, (the "License");
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 * Fuzz the SCT parser.
13 */
14
15#include <stdio.h>
16#include <openssl/ct.h>
Kurt Roeckxd69d8f92016-12-02 19:34:54 +010017#include <openssl/err.h>
Ben Laurie4a2c4c12016-06-03 11:07:42 +010018#include "fuzzer.h"
19
Kurt Roeckxf3e911d2016-11-19 17:10:35 +010020int FuzzerInitialize(int *argc, char ***argv)
21{
Kurt Roeckxd69d8f92016-12-02 19:34:54 +010022 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
23 CRYPTO_free_ex_index(0, -1);
24 ERR_get_state();
Ben Laurie90d28f02016-06-04 16:10:49 +010025 return 1;
26}
27
Kurt Roeckxf3e911d2016-11-19 17:10:35 +010028int FuzzerTestOneInput(const uint8_t *buf, size_t len)
29{
Ben Laurie4a2c4c12016-06-03 11:07:42 +010030 const uint8_t **pp = &buf;
Kurt Roeckxe10aeee2016-07-16 13:41:33 +020031 unsigned char *der = NULL;
Ben Laurie4a2c4c12016-06-03 11:07:42 +010032 STACK_OF(SCT) *scts = d2i_SCT_LIST(NULL, pp, len);
Kurt Roeckxe10aeee2016-07-16 13:41:33 +020033 if (scts != NULL) {
34 BIO *bio = BIO_new(BIO_s_null());
35 SCT_LIST_print(scts, bio, 4, "\n", NULL);
36 BIO_free(bio);
37
Matt Caswell33e49fd2016-07-18 10:28:45 +010038 if (i2d_SCT_LIST(scts, &der)) {
39 /* Silence unused result warning */
40 }
Kurt Roeckxe10aeee2016-07-16 13:41:33 +020041 OPENSSL_free(der);
42
43 SCT_LIST_free(scts);
44 }
Kurt Roeckxd69d8f92016-12-02 19:34:54 +010045 ERR_clear_error();
Ben Laurie4a2c4c12016-06-03 11:07:42 +010046 return 0;
47}
Kurt Roeckxad4da7f2016-11-19 17:13:10 +010048
49void FuzzerCleanup(void)
50{
51}