Coverage Report

Created: 2025-07-18 06:40

/src/h2o/fuzz/driver_url.cc
Line
Count
Source
1
/*
2
 * Copyright (c) 2016 Fastly, Inc.
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to
6
 * deal in the Software without restriction, including without limitation the
7
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
 * sell copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in
12
 * all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
 * IN THE SOFTWARE.
21
 */
22
23
/*
24
 * This file implements a test harness for using h2o with LibFuzzer.
25
 * See http://llvm.org/docs/LibFuzzer.html for more info.
26
 */
27
#define H2O_USE_EPOLL 1
28
29
#include "h2o.h"
30
#include "h2o/url.h"
31
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
32
550
{
33
550
    h2o_mem_pool_t pool;
34
550
    h2o_url_t url;
35
550
    int ret;
36
37
550
    h2o_mem_init_pool(&pool);
38
39
550
    ret = h2o_url_parse(&pool, (const char *)Data, Size, &url);
40
550
    if (ret != -1) {
41
382
        size_t total = 0, i;
42
382
        assert(url.scheme != NULL);
43
5.53M
        for (i = 0; i < url.authority.len; i++)
44
5.53M
            if (url.authority.base[i])
45
5.40M
                total++;
46
5.52M
        for (i = 0; i < url.host.len; i++)
47
5.52M
            if (url.host.base[i])
48
5.39M
                total++;
49
9.23M
        for (i = 0; i < url.path.len; i++)
50
9.23M
            if (url.path.base[i])
51
8.94M
                total++;
52
382
        assert(total <= Size * 2);
53
382
    }
54
55
550
    h2o_mem_clear_pool(&pool);
56
550
    return 0;
57
550
}