Coverage Report

Created: 2025-12-21 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uriparser/fuzz/DissectQueryMallocFuzzer.cpp
Line
Count
Source
1
// Copyright 2020 Google LLC
2
// Copyright 2025 Mikhail Khachaiants <mkhachaiants@gmail.com>
3
//
4
// Licensed under the Apache License, Version 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
//
8
//      http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
// distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15
16
#include "uriparser/Uri.h"
17
#include "FuzzingUtils.h"
18
#include <cstddef>
19
#include <cstdint>
20
#include <utility>
21
#include <vector>
22
23
5.94k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) {
24
5.94k
    FuzzedDataProvider fdp(data, size);
25
5.94k
    const UriString query = consumeRemainingBytesAsString(fdp);
26
27
5.94k
    URI_TYPE(QueryList) * query_list = nullptr;
28
5.94k
    int item_count = -1;
29
30
5.94k
    const URI_CHAR * query_start = query.c_str();
31
5.94k
    const URI_CHAR * query_end = query_start + query.size();
32
33
    // Break a query like "a=b&2=3" into key/value pairs.
34
5.94k
    int result =
35
5.94k
        URI_FUNC(DissectQueryMalloc)(&query_list, &item_count, query_start, query_end);
36
37
5.94k
    if (query_list == nullptr || result != URI_SUCCESS || item_count < 0) {
38
62
        return 0;
39
62
    }
40
41
5.88k
    int chars_required = 0;
42
5.88k
    if (URI_FUNC(ComposeQueryCharsRequired)(query_list, &chars_required) != URI_SUCCESS) {
43
0
        return 0;
44
0
    }
45
46
5.88k
    if (!chars_required) {
47
12
        URI_FUNC(FreeQueryList)(query_list);
48
12
        return 0;
49
12
    }
50
51
    // URI_FUNC(ComposeQuery) requires number of characters including terminator
52
5.87k
    const int buf_size = chars_required + 1;
53
54
5.87k
    std::vector<URI_CHAR> buf(buf_size, 0);
55
5.87k
    int written = -1;
56
57
    // Reverse the process of uriDissectQueryMallocA.
58
5.87k
    result = URI_FUNC(ComposeQuery)(buf.data(), query_list, buf_size, &written);
59
60
5.87k
    URI_FUNC(FreeQueryList)(query_list);
61
5.87k
    return 0;
62
5.88k
}
LLVMFuzzerTestOneInput
Line
Count
Source
23
2.97k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) {
24
2.97k
    FuzzedDataProvider fdp(data, size);
25
2.97k
    const UriString query = consumeRemainingBytesAsString(fdp);
26
27
2.97k
    URI_TYPE(QueryList) * query_list = nullptr;
28
2.97k
    int item_count = -1;
29
30
2.97k
    const URI_CHAR * query_start = query.c_str();
31
2.97k
    const URI_CHAR * query_end = query_start + query.size();
32
33
    // Break a query like "a=b&2=3" into key/value pairs.
34
2.97k
    int result =
35
2.97k
        URI_FUNC(DissectQueryMalloc)(&query_list, &item_count, query_start, query_end);
36
37
2.97k
    if (query_list == nullptr || result != URI_SUCCESS || item_count < 0) {
38
31
        return 0;
39
31
    }
40
41
2.94k
    int chars_required = 0;
42
2.94k
    if (URI_FUNC(ComposeQueryCharsRequired)(query_list, &chars_required) != URI_SUCCESS) {
43
0
        return 0;
44
0
    }
45
46
2.94k
    if (!chars_required) {
47
6
        URI_FUNC(FreeQueryList)(query_list);
48
6
        return 0;
49
6
    }
50
51
    // URI_FUNC(ComposeQuery) requires number of characters including terminator
52
2.93k
    const int buf_size = chars_required + 1;
53
54
2.93k
    std::vector<URI_CHAR> buf(buf_size, 0);
55
2.93k
    int written = -1;
56
57
    // Reverse the process of uriDissectQueryMallocA.
58
2.93k
    result = URI_FUNC(ComposeQuery)(buf.data(), query_list, buf_size, &written);
59
60
2.93k
    URI_FUNC(FreeQueryList)(query_list);
61
2.93k
    return 0;
62
2.94k
}
LLVMFuzzerTestOneInput
Line
Count
Source
23
2.97k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) {
24
2.97k
    FuzzedDataProvider fdp(data, size);
25
2.97k
    const UriString query = consumeRemainingBytesAsString(fdp);
26
27
2.97k
    URI_TYPE(QueryList) * query_list = nullptr;
28
2.97k
    int item_count = -1;
29
30
2.97k
    const URI_CHAR * query_start = query.c_str();
31
2.97k
    const URI_CHAR * query_end = query_start + query.size();
32
33
    // Break a query like "a=b&2=3" into key/value pairs.
34
2.97k
    int result =
35
2.97k
        URI_FUNC(DissectQueryMalloc)(&query_list, &item_count, query_start, query_end);
36
37
2.97k
    if (query_list == nullptr || result != URI_SUCCESS || item_count < 0) {
38
31
        return 0;
39
31
    }
40
41
2.94k
    int chars_required = 0;
42
2.94k
    if (URI_FUNC(ComposeQueryCharsRequired)(query_list, &chars_required) != URI_SUCCESS) {
43
0
        return 0;
44
0
    }
45
46
2.94k
    if (!chars_required) {
47
6
        URI_FUNC(FreeQueryList)(query_list);
48
6
        return 0;
49
6
    }
50
51
    // URI_FUNC(ComposeQuery) requires number of characters including terminator
52
2.93k
    const int buf_size = chars_required + 1;
53
54
2.93k
    std::vector<URI_CHAR> buf(buf_size, 0);
55
2.93k
    int written = -1;
56
57
    // Reverse the process of uriDissectQueryMallocA.
58
2.93k
    result = URI_FUNC(ComposeQuery)(buf.data(), query_list, buf_size, &written);
59
60
2.93k
    URI_FUNC(FreeQueryList)(query_list);
61
2.93k
    return 0;
62
2.94k
}