Coverage Report

Created: 2026-03-28 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/tests/fuzzing/fuzz_json.cc
Line
Count
Source
1
/** @file
2
3
  fuzzing mgmt/rpc/jsonrpc
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 "mgmt/rpc/jsonrpc/JsonRPCManager.h"
25
#include "mgmt/rpc/jsonrpc/JsonRPC.h"
26
#include "mgmt/rpc/handlers/common/ErrorUtils.h"
27
#include "tscore/Diags.h"
28
29
21.8k
#define kMinInputLength 5
30
10.8k
#define kMaxInputLength 1024
31
32
// Not using the singleton logic.
33
struct JsonRpcUnitTest : rpc::JsonRPCManager {
34
5.52k
  JsonRpcUnitTest() : JsonRPCManager() {}
35
  using base = JsonRPCManager;
36
  bool
37
  remove_handler(std::string const &name)
38
0
  {
39
0
    return base::remove_handler(name);
40
0
  }
41
  template <typename Func>
42
  bool
43
  add_notification_handler(const std::string &name, Func &&call)
44
  {
45
    return base::add_notification_handler(name, std::forward<Func>(call), nullptr, {});
46
  }
47
  template <typename Func>
48
  bool
49
  add_method_handler(const std::string &name, Func &&call)
50
  {
51
    return base::add_method_handler(name, std::forward<Func>(call), nullptr, {});
52
  }
53
54
  std::optional<std::string>
55
  handle_call(std::string const &jsonString)
56
5.52k
  {
57
5.52k
    return base::handle_call(rpc::Context{}, jsonString);
58
5.52k
  }
59
};
60
61
extern "C" int
62
LLVMFuzzerTestOneInput(const uint8_t *input_data, size_t size_data)
63
10.9k
{
64
10.9k
  if (size_data < kMinInputLength || size_data > kMaxInputLength) {
65
128
    return 1;
66
128
  }
67
68
10.7k
  std::string input(reinterpret_cast<const char *>(input_data), size_data);
69
70
10.7k
  DiagsPtr::set(new Diags("fuzzing", "", "", nullptr));
71
72
10.7k
  JsonRpcUnitTest rpc;
73
10.7k
  rpc.handle_call(input);
74
75
10.7k
  delete diags();
76
77
10.7k
  return 0;
78
10.9k
}