Coverage Report

Created: 2024-05-21 06:11

/proc/self/cwd/string_utilities_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2020 Google Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
17
#include <string>
18
19
#include <fuzzer/FuzzedDataProvider.h>
20
21
#include "absl/strings/str_format.h"
22
#include "absl/strings/str_join.h"
23
#include "absl/strings/str_split.h"
24
#include "absl/strings/numbers.h"
25
#include "absl/strings/str_cat.h"
26
27
28
1.28k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
29
1.28k
  FuzzedDataProvider fuzzed_data(data, size);
30
1.28k
  float float_value = fuzzed_data.ConsumeFloatingPoint<float>();
31
1.28k
  double double_value = fuzzed_data.ConsumeFloatingPoint<double>();
32
1.28k
  int int_value = fuzzed_data.ConsumeIntegral<int>();
33
1.28k
  bool bool_value = fuzzed_data.ConsumeBool();
34
1.28k
  std::string str1 = fuzzed_data.ConsumeRandomLengthString();
35
1.28k
  std::string str2 = fuzzed_data.ConsumeRemainingBytesAsString();
36
37
1.28k
  std::string float_str = absl::StrFormat("%g", float_value);
38
1.28k
  std::string double_str = absl::StrFormat("%g", double_value);
39
1.28k
  std::string int_str = absl::StrFormat("%d", int_value);
40
1.28k
  std::string bool_str = absl::StrFormat("%d", bool_value);
41
  
42
1.28k
  if (!absl::SimpleAtof(float_str, &float_value))
43
0
    return 0;
44
1.28k
  if (!absl::SimpleAtod(double_str, &double_value))
45
0
    return 0;
46
1.28k
  if (!absl::SimpleAtoi(int_str, &int_value))
47
0
    return 0;
48
1.28k
  if (!absl::SimpleAtob(bool_str, &bool_value))
49
0
    return 0;
50
51
1.28k
  absl::StrAppend(&str1, str2);
52
1.28k
  std::string str_result = absl::StrCat(str1, float_value, double_value, int_value, bool_value);
53
1.28k
  std::vector<std::string> v = absl::StrSplit(str_result, ".");
54
1.28k
  absl::StrJoin(v, ".");
55
1.28k
  return 0;
56
1.28k
}