• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

open-source-parsers / jsoncpp / 12134745591

03 Dec 2024 07:16AM CUT coverage: 95.295%. Remained the same
12134745591

push

github

web-flow
Merge d350f8286 into 2b3815c90

5306 of 5568 relevant lines covered (95.29%)

11935.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.0
/src/test_lib_json/fuzz.cpp
1
// Copyright 2007-2019 The JsonCpp Authors
2
// Distributed under MIT license, or public domain if desired and
3
// recognized in your jurisdiction.
4
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5

6
#include "fuzz.h"
7

8
#include <cstdint>
9
#include <json/config.h>
10
#include <json/json.h>
11
#include <memory>
12
#include <string>
13

14
namespace Json {
15
class Exception;
16
}
17

18
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
1✔
19
  Json::CharReaderBuilder builder;
1✔
20

21
  if (size < sizeof(uint32_t)) {
1✔
22
    return 0;
23
  }
24

25
  const uint32_t hash_settings = static_cast<uint32_t>(data[0]) |
×
26
                                 (static_cast<uint32_t>(data[1]) << 8) |
×
27
                                 (static_cast<uint32_t>(data[2]) << 16) |
×
28
                                 (static_cast<uint32_t>(data[3]) << 24);
×
29
  data += sizeof(uint32_t);
×
30
  size -= sizeof(uint32_t);
31

32
  builder.settings_["failIfExtra"] = hash_settings & (1 << 0);
×
33
  builder.settings_["allowComments_"] = hash_settings & (1 << 1);
×
34
  builder.settings_["strictRoot_"] = hash_settings & (1 << 2);
×
35
  builder.settings_["allowDroppedNullPlaceholders_"] = hash_settings & (1 << 3);
×
36
  builder.settings_["allowNumericKeys_"] = hash_settings & (1 << 4);
×
37
  builder.settings_["allowSingleQuotes_"] = hash_settings & (1 << 5);
×
38
  builder.settings_["failIfExtra_"] = hash_settings & (1 << 6);
×
39
  builder.settings_["rejectDupKeys_"] = hash_settings & (1 << 7);
×
40
  builder.settings_["allowSpecialFloats_"] = hash_settings & (1 << 8);
×
41
  builder.settings_["collectComments"] = hash_settings & (1 << 9);
×
42
  builder.settings_["allowTrailingCommas_"] = hash_settings & (1 << 10);
×
43

44
  std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
×
45

46
  Json::Value root;
×
47
  const auto data_str = reinterpret_cast<const char*>(data);
48
  try {
49
    reader->parse(data_str, data_str + size, &root, nullptr);
×
50
  } catch (Json::Exception const&) {
×
51
  }
×
52
  // Whether it succeeded or not doesn't matter.
53
  return 0;
54
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc