Coverage Report

Created: 2026-09-12 06:55

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
1.62k
{
21
1.62k
    OSSL_ECHSTORE *es;
22
1.62k
    BIO *in;
23
24
1.62k
    es = OSSL_ECHSTORE_new(NULL, NULL);
25
1.62k
    if (es == NULL)
26
0
        return;
27
28
1.62k
    in = BIO_new_mem_buf(buf, len);
29
1.62k
    if (in == NULL) {
30
0
        OSSL_ECHSTORE_free(es);
31
0
        return;
32
0
    }
33
34
1.62k
    OSSL_ECHSTORE_read_echconfiglist(es, in);
35
36
1.62k
    OSSL_ECHSTORE_free(es);
37
1.62k
    BIO_free(in);
38
1.62k
}
39
40
int FuzzerInitialize(int *argc, char ***argv)
41
229
{
42
229
    return 1;
43
229
}
44
45
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
46
899
{
47
899
    uint8_t *fixed_buf = NULL;
48
899
    int bio_len;
49
899
    uint16_t outer_len, inner_len;
50
51
899
    if (len > INT_MAX)
52
0
        return 0;
53
899
    bio_len = (int)len;
54
55
    /* Target raw without any fixup */
56
899
    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
899
    if (len < OSSL_ECH_MIN_ECHCONFIG_LEN || len >= OSSL_ECH_MAX_ECHCONFIG_LEN)
64
171
        goto end;
65
728
    outer_len = (uint16_t)(len - 2);
66
728
    inner_len = (uint16_t)(len - 6);
67
68
728
    fixed_buf = OPENSSL_memdup(buf, len);
69
728
    if (fixed_buf == NULL)
70
0
        goto end;
71
72
    /* Fix up to pass initial checks*/
73
728
    OPENSSL_store_u16_be(fixed_buf, outer_len);
74
728
    OPENSSL_store_u16_be(fixed_buf + 2, OSSL_ECH_RFC9849_VERSION);
75
728
    OPENSSL_store_u16_be(fixed_buf + 4, inner_len);
76
77
728
    parse_one(fixed_buf, bio_len);
78
79
899
end:
80
899
    OPENSSL_free(fixed_buf);
81
899
    ERR_clear_error();
82
83
899
    return 0;
84
728
}
85
86
void FuzzerCleanup(void)
87
0
{
88
0
}