Coverage Report

Created: 2026-06-15 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Tests/Fuzzing/cmCMakePathFuzzer.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
4
/*
5
 * Fuzzer for CMake's path manipulation (cmCMakePath)
6
 *
7
 * Tests path parsing, normalization, and manipulation operations.
8
 */
9
10
#include <cstddef>
11
#include <cstdint>
12
#include <string>
13
14
#include "cmCMakePath.h"
15
16
static constexpr size_t kMaxInputSize = 4096;
17
18
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
19
384
{
20
384
  if (size == 0 || size > kMaxInputSize) {
21
19
    return 0;
22
19
  }
23
24
365
  std::string input(reinterpret_cast<char const*>(data), size);
25
26
  // Test various path operations
27
365
  cmCMakePath path(input);
28
29
  // Basic queries
30
365
  (void)path.IsEmpty();
31
365
  (void)path.HasRootPath();
32
365
  (void)path.HasRootName();
33
365
  (void)path.HasRootDirectory();
34
365
  (void)path.HasRelativePath();
35
365
  (void)path.HasParentPath();
36
365
  (void)path.HasFileName();
37
365
  (void)path.HasStem();
38
365
  (void)path.HasExtension();
39
365
  (void)path.IsAbsolute();
40
365
  (void)path.IsRelative();
41
42
  // Component extraction
43
365
  (void)path.GetRootName();
44
365
  (void)path.GetRootDirectory();
45
365
  (void)path.GetRootPath();
46
365
  (void)path.GetRelativePath();
47
365
  (void)path.GetParentPath();
48
365
  (void)path.GetFileName();
49
365
  (void)path.GetExtension();
50
365
  (void)path.GetStem();
51
365
  (void)path.String();
52
365
  (void)path.GenericString();
53
54
  // Manipulation
55
365
  cmCMakePath normalized = path.Normal();
56
365
  (void)normalized.String();
57
58
  // If we have two paths in input, test operations between them
59
365
  size_t midpoint = size / 2;
60
365
  if (midpoint > 0) {
61
362
    std::string input1(reinterpret_cast<char const*>(data), midpoint);
62
362
    std::string input2(reinterpret_cast<char const*>(data + midpoint),
63
362
                       size - midpoint);
64
65
362
    cmCMakePath path1(input1);
66
362
    cmCMakePath path2(input2);
67
68
    // Append operations
69
362
    cmCMakePath appended = path1 / path2;
70
362
    (void)appended.String();
71
72
    // Comparison
73
362
    (void)(path1 == path2);
74
362
  }
75
76
365
  return 0;
77
384
}