Coverage Report

Created: 2024-05-21 06:11

/proc/self/cwd/string_escape_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 "absl/strings/escaping.h"
20
21
489
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22
489
  std::string str (reinterpret_cast<const char*>(data), size);
23
489
  std::string escaped, unescaped;
24
489
  escaped = absl::CHexEscape(str);
25
489
  absl::CUnescape(escaped, &unescaped);
26
489
  if (str != unescaped)
27
0
    abort();
28
29
489
  escaped = absl::CEscape(str);
30
489
  absl::CUnescape(escaped, &unescaped);
31
489
  if (str != unescaped)
32
0
    abort();
33
34
489
  escaped = absl::Utf8SafeCEscape(str);
35
489
  absl::CUnescape(escaped, &unescaped);
36
489
  if (str != unescaped)
37
0
    abort();
38
  
39
489
  escaped = absl::Utf8SafeCHexEscape(str);
40
489
  absl::CUnescape(escaped, &unescaped);
41
489
  if (str != unescaped)
42
0
    abort();
43
  
44
489
  std::string encoded, decoded;
45
489
  absl::Base64Escape(str, &encoded);
46
489
  absl::Base64Unescape(encoded, &decoded);
47
489
  if (str != unescaped)
48
0
    abort();
49
50
489
  absl::WebSafeBase64Escape(str, &encoded);
51
489
  absl::WebSafeBase64Unescape(encoded, &decoded);
52
489
  if (str != decoded)
53
0
    abort();
54
55
489
  std::string hex_result, bytes_result;
56
489
  hex_result = absl::BytesToHexString(str);
57
489
  bytes_result = absl::HexStringToBytes(hex_result);
58
489
  if (str != decoded)
59
0
    abort();
60
61
489
  return 0;
62
489
}