File: cmStringAlgorithmsFuzzer.cxx

package info (click to toggle)
cmake 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 158,704 kB
  • sloc: ansic: 406,077; cpp: 309,512; sh: 4,233; python: 3,696; yacc: 3,109; lex: 1,279; f90: 538; asm: 471; lisp: 375; java: 310; cs: 270; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 110; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22; sed: 2
file content (75 lines) | stat: -rw-r--r-- 2,124 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */

/*
 * Fuzzer for CMake's string algorithms
 *
 * Tests string manipulation, escaping, and processing functions.
 */

#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>

#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"

static constexpr size_t kMaxInputSize = 16 * 1024;

extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
  if (size == 0 || size > kMaxInputSize) {
    return 0;
  }

  std::string input(reinterpret_cast<char const*>(data), size);

  // Test string manipulation functions
  (void)cmTrimWhitespace(input);
  (void)cmRemoveQuotes(input);
  (void)cmEscapeQuotes(input);

  // Test case conversion
  (void)cmSystemTools::UpperCase(input);
  (void)cmSystemTools::LowerCase(input);

  // Test tokenization
  std::vector<std::string> tokens = cmTokenize(input, " \t\n\r");
  (void)tokens.size();

  // Test with different separators if input is large enough
  if (size > 4) {
    std::string sep(reinterpret_cast<char const*>(data), 2);
    std::string str(reinterpret_cast<char const*>(data + 2), size - 2);
    std::vector<std::string> parts = cmTokenize(str, sep);
    (void)parts.size();
  }

  // Test join operations
  if (!tokens.empty()) {
    (void)cmJoin(tokens, ";");
    (void)cmJoin(tokens, ",");
  }

  // Test string contains
  if (size > 2) {
    std::string haystack(reinterpret_cast<char const*>(data), size / 2);
    std::string needle(reinterpret_cast<char const*>(data + size / 2),
                       size - size / 2);
    (void)cmHasPrefix(haystack, needle);
    (void)cmHasSuffix(haystack, needle);
  }

  // Test path operations
  (void)cmSystemTools::GetFilenameWithoutExtension(input);
  (void)cmSystemTools::GetFilenameExtension(input);
  (void)cmSystemTools::GetFilenameName(input);
  (void)cmSystemTools::GetFilenameLastExtension(input);
  (void)cmSystemTools::GetFilenamePath(input);

  // Test path normalization
  (void)cmSystemTools::CollapseFullPath(input);

  return 0;
}