Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/fuzz/x509v3.c
Line
Count
Source
1
/*
2
 * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (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
#include <openssl/bio.h>
11
#include <openssl/conf.h>
12
#include <openssl/err.h>
13
#include <openssl/x509.h>
14
#include <openssl/x509v3.h>
15
#include "fuzzer.h"
16
17
/*
18
 * Repeated section references in the string-based extension APIs can cause
19
 * quadratic output growth. Limit input size
20
 * to keep individual fuzzing iterations small. See:
21
 * https://github.com/google/boringssl/blob/f1f2556a5dfa59e147d9d47279cc3f7f8a18b433/fuzz/conf.cc#L22-L25
22
 * https://issues.chromium.org/issues/42290485
23
 */
24
22.6k
#define MAX_INPUT_SIZE (8 * 1024)
25
26
int FuzzerInitialize(int *argc, char ***argv)
27
254
{
28
254
    return 1;
29
254
}
30
31
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
32
22.6k
{
33
22.6k
    BIO *in = NULL;
34
22.6k
    CONF *conf = NULL;
35
22.6k
    X509 *cert = NULL;
36
22.6k
    X509V3_CTX ctx;
37
38
22.6k
    if (len == 0)
39
0
        return 0;
40
41
22.6k
    if (len > MAX_INPUT_SIZE)
42
15
        len = MAX_INPUT_SIZE;
43
44
22.6k
    in = BIO_new(BIO_s_mem());
45
22.6k
    if (in == NULL)
46
0
        goto end;
47
48
22.6k
    if ((size_t)BIO_write(in, buf, (int)len) != len)
49
0
        goto end;
50
51
22.6k
    conf = NCONF_new(NULL);
52
22.6k
    if (conf == NULL)
53
0
        goto end;
54
55
22.6k
    if (NCONF_load_bio(conf, in, NULL) <= 0)
56
1.74k
        goto end;
57
58
20.9k
    cert = X509_new();
59
20.9k
    if (cert != NULL) {
60
20.9k
        X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
61
20.9k
        X509V3_set_nconf(&ctx, conf);
62
20.9k
        X509V3_EXT_add_nconf(conf, &ctx, "default", cert);
63
20.9k
        X509_free(cert);
64
20.9k
    }
65
66
20.9k
    cert = X509_new();
67
20.9k
    if (cert != NULL) {
68
20.9k
        X509V3_set_ctx(&ctx, NULL, NULL, NULL, NULL, 0);
69
20.9k
        X509V3_set_nconf(&ctx, conf);
70
20.9k
        X509V3_EXT_add_nconf(conf, &ctx, "default", cert);
71
20.9k
    }
72
73
22.6k
end:
74
22.6k
    X509_free(cert);
75
22.6k
    NCONF_free(conf);
76
22.6k
    BIO_free(in);
77
22.6k
    ERR_clear_error();
78
79
22.6k
    return 0;
80
20.9k
}
81
82
void FuzzerCleanup(void)
83
0
{
84
0
}