Coverage Report

Created: 2026-05-21 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/tests/fuzzing/fuzz_http.cc
Line
Count
Source
1
/** @file
2
3
  fuzzing proxy/hdrs & proxy/http
4
5
  @section license License
6
7
  Licensed to the Apache Software Foundation (ASF) under one
8
  or more contributor license agreements.  See the NOTICE file
9
  distributed with this work for additional information
10
  regarding copyright ownership.  The ASF licenses this file
11
  to you under the Apache License, Version 2.0 (the
12
  "License"); you may not use this file except in compliance
13
  with the License.  You may obtain a copy of the License at
14
15
      http://www.apache.org/licenses/LICENSE-2.0
16
17
  Unless required by applicable law or agreed to in writing, software
18
  distributed under the License is distributed on an "AS IS" BASIS,
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
  See the License for the specific language governing permissions and
21
  limitations under the License.
22
 */
23
24
#include "proxy/hdrs/HTTP.h"
25
#include "proxy/hdrs/HttpCompat.h"
26
#include "tscore/Diags.h"
27
28
18.2k
#define kMinInputLength 10
29
9.10k
#define kMaxInputLength 1024
30
31
extern int cmd_disable_pfreelist;
32
33
extern "C" int
34
LLVMFuzzerTestOneInput(const uint8_t *input_data, size_t size_data)
35
9.12k
{
36
9.12k
  if (size_data < kMinInputLength || size_data > kMaxInputLength) {
37
103
    return 0;
38
103
  }
39
40
9.02k
  std::string input(reinterpret_cast<const char *>(input_data), size_data);
41
9.02k
  char const *start = input.c_str();
42
9.02k
  char const *end   = input.c_str() + input.size();
43
44
9.02k
  cmd_disable_pfreelist = true;
45
9.02k
  DiagsPtr::set(new Diags("fuzzing", "", "", nullptr));
46
47
9.02k
  http_init();
48
49
9.02k
  HTTPParser parser;
50
9.02k
  HTTPHdr    req_hdr, rsp_hdr, req_hdr_2, rsp_hdr_2, req_hdr_3, rsp_hdr_3;
51
52
9.02k
  req_hdr.create(HTTPType::REQUEST);
53
9.02k
  rsp_hdr.create(HTTPType::RESPONSE);
54
9.02k
  req_hdr_2.create(HTTPType::REQUEST, HTTP_2_0);
55
9.02k
  rsp_hdr_2.create(HTTPType::RESPONSE, HTTP_2_0);
56
9.02k
  req_hdr_3.create(HTTPType::REQUEST, HTTP_3_0);
57
9.02k
  rsp_hdr_3.create(HTTPType::RESPONSE, HTTP_3_0);
58
59
9.02k
  {
60
9.02k
    http_parser_init(&parser);
61
9.02k
    ParseResult result = req_hdr.parse_req(&parser, &start, end, true);
62
9.02k
    http_parser_clear(&parser);
63
9.02k
  }
64
9.02k
  {
65
9.02k
    http_parser_init(&parser);
66
9.02k
    ParseResult result = rsp_hdr.parse_resp(&parser, &start, end, true);
67
9.02k
    http_parser_clear(&parser);
68
9.02k
  }
69
9.02k
  {
70
9.02k
    http_parser_init(&parser);
71
9.02k
    ParseResult result = req_hdr_2.parse_req(&parser, &start, end, true);
72
9.02k
    http_parser_clear(&parser);
73
9.02k
  }
74
9.02k
  {
75
9.02k
    http_parser_init(&parser);
76
9.02k
    ParseResult result = rsp_hdr_2.parse_resp(&parser, &start, end, true);
77
9.02k
    http_parser_clear(&parser);
78
9.02k
  }
79
9.02k
  {
80
9.02k
    http_parser_init(&parser);
81
9.02k
    ParseResult result = req_hdr_3.parse_req(&parser, &start, end, true);
82
9.02k
    http_parser_clear(&parser);
83
9.02k
  }
84
9.02k
  {
85
9.02k
    http_parser_init(&parser);
86
9.02k
    ParseResult result = rsp_hdr_3.parse_resp(&parser, &start, end, true);
87
9.02k
    http_parser_clear(&parser);
88
9.02k
  }
89
90
9.02k
  req_hdr.destroy();
91
9.02k
  rsp_hdr.destroy();
92
9.02k
  req_hdr_2.destroy();
93
9.02k
  rsp_hdr_2.destroy();
94
9.02k
  req_hdr_3.destroy();
95
9.02k
  rsp_hdr_3.destroy();
96
97
9.02k
  delete diags();
98
99
9.02k
  return 0;
100
9.12k
}