Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/fuzz/echconfiglist_parser.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 <limits.h>
11
#include <openssl/ech.h>
12
#include <openssl/err.h>
13
#include <openssl/bio.h>
14
#include <openssl/crypto.h>
15
#include <openssl/e_os2.h>
16
#include <openssl/byteorder.h>
17
#include "fuzzer.h"
18
19
static void parse_one(const uint8_t *buf, int len)
20
3.40k
{
21
3.40k
    OSSL_ECHSTORE *es;
22
3.40k
    BIO *in;
23
24
3.40k
    es = OSSL_ECHSTORE_new(NULL, NULL);
25
3.40k
    if (es == NULL)
26
0
        return;
27
28
3.40k
    in = BIO_new_mem_buf(buf, len);
29
3.40k
    if (in == NULL) {
30
0
        OSSL_ECHSTORE_free(es);
31
0
        return;
32
0
    }
33
34
3.40k
    OSSL_ECHSTORE_read_echconfiglist(es, in);
35
36
3.40k
    OSSL_ECHSTORE_free(es);
37
3.40k
    BIO_free(in);
38
3.40k
}
39
40
int FuzzerInitialize(int *argc, char ***argv)
41
254
{
42
254
    return 1;
43
254
}
44
45
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
46
1.86k
{
47
1.86k
    uint8_t *fixed_buf = NULL;
48
1.86k
    int bio_len;
49
1.86k
    uint16_t outer_len, inner_len;
50
51
1.86k
    if (len > INT_MAX)
52
0
        return 0;
53
1.86k
    bio_len = (int)len;
54
55
    /* Target raw without any fixup */
56
1.86k
    parse_one(buf, bio_len);
57
58
    /*
59
     * ech_decode_and_flatten has a strict size check:
60
     * OSSL_ECH_MIN_ECHCONFIG_LEN = 32
61
     * OSSL_ECH_MAX_ECHCONFIG_LEN = 1500
62
     */
63
1.86k
    if (len < OSSL_ECH_MIN_ECHCONFIG_LEN || len >= OSSL_ECH_MAX_ECHCONFIG_LEN)
64
330
        goto end;
65
1.53k
    outer_len = (uint16_t)(len - 2);
66
1.53k
    inner_len = (uint16_t)(len - 6);
67
68
1.53k
    fixed_buf = OPENSSL_memdup(buf, len);
69
1.53k
    if (fixed_buf == NULL)
70
0
        goto end;
71
72
    /* Fix up to pass initial checks*/
73
1.53k
    OPENSSL_store_u16_be(fixed_buf, outer_len);
74
1.53k
    OPENSSL_store_u16_be(fixed_buf + 2, OSSL_ECH_RFC9849_VERSION);
75
1.53k
    OPENSSL_store_u16_be(fixed_buf + 4, inner_len);
76
77
1.53k
    parse_one(fixed_buf, bio_len);
78
79
1.86k
end:
80
1.86k
    OPENSSL_free(fixed_buf);
81
1.86k
    ERR_clear_error();
82
83
1.86k
    return 0;
84
1.53k
}
85
86
void FuzzerCleanup(void)
87
0
{
88
0
}