Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/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
9.43k
#define MAX_INPUT_SIZE (8 * 1024)
25
26
int FuzzerInitialize(int *argc, char ***argv)
27
229
{
28
229
    return 1;
29
229
}
30
31
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
32
9.42k
{
33
9.42k
    BIO *in = NULL;
34
9.42k
    CONF *conf = NULL;
35
9.42k
    X509 *cert = NULL;
36
9.42k
    X509V3_CTX ctx;
37
38
9.42k
    if (len == 0)
39
0
        return 0;
40
41
9.42k
    if (len > MAX_INPUT_SIZE)
42
9
        len = MAX_INPUT_SIZE;
43
44
9.42k
    in = BIO_new(BIO_s_mem());
45
9.42k
    if (in == NULL)
46
0
        goto end;
47
48
9.42k
    if ((size_t)BIO_write(in, buf, (int)len) != len)
49
0
        goto end;
50
51
9.42k
    conf = NCONF_new(NULL);
52
9.42k
    if (conf == NULL)
53
0
        goto end;
54
55
9.42k
    if (NCONF_load_bio(conf, in, NULL) <= 0)
56
826
        goto end;
57
58
8.59k
    cert = X509_new();
59
8.59k
    if (cert != NULL) {
60
8.59k
        X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
61
8.59k
        X509V3_set_nconf(&ctx, conf);
62
8.59k
        X509V3_EXT_add_nconf(conf, &ctx, "default", cert);
63
8.59k
        X509_free(cert);
64
8.59k
    }
65
66
8.59k
    cert = X509_new();
67
8.59k
    if (cert != NULL) {
68
8.59k
        X509V3_set_ctx(&ctx, NULL, NULL, NULL, NULL, 0);
69
8.59k
        X509V3_set_nconf(&ctx, conf);
70
8.59k
        X509V3_EXT_add_nconf(conf, &ctx, "default", cert);
71
8.59k
    }
72
73
9.42k
end:
74
9.42k
    X509_free(cert);
75
9.42k
    NCONF_free(conf);
76
9.42k
    BIO_free(in);
77
9.42k
    ERR_clear_error();
78
79
9.42k
    return 0;
80
8.59k
}
81
82
void FuzzerCleanup(void)
83
0
{
84
0
}