Coverage Report

Created: 2026-07-30 06:52

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
376
{
20
376
  if (size == 0 || size > kMaxInputSize) {
21
19
    return 0;
22
19
  }
23
24
357
  std::string input(reinterpret_cast<char const*>(data), size);
25
26
  // Test various path operations
27
357
  cmCMakePath path(input);
28
29
  // Basic queries
30
357
  (void)path.IsEmpty();
31
357
  (void)path.HasRootPath();
32
357
  (void)path.HasRootName();
33
357
  (void)path.HasRootDirectory();
34
357
  (void)path.HasRelativePath();
35
357
  (void)path.HasParentPath();
36
357
  (void)path.HasFileName();
37
357
  (void)path.HasStem();
38
357
  (void)path.HasExtension();
39
357
  (void)path.IsAbsolute();
40
357
  (void)path.IsRelative();
41
42
  // Component extraction
43
357
  (void)path.GetRootName();
44
357
  (void)path.GetRootDirectory();
45
357
  (void)path.GetRootPath();
46
357
  (void)path.GetRelativePath();
47
357
  (void)path.GetParentPath();
48
357
  (void)path.GetFileName();
49
357
  (void)path.GetExtension();
50
357
  (void)path.GetStem();
51
357
  (void)path.String();
52
357
  (void)path.GenericString();
53
54
  // Manipulation
55
357
  cmCMakePath normalized = path.Normal();
56
357
  (void)normalized.String();
57
58
  // If we have two paths in input, test operations between them
59
357
  size_t midpoint = size / 2;
60
357
  if (midpoint > 0) {
61
354
    std::string input1(reinterpret_cast<char const*>(data), midpoint);
62
354
    std::string input2(reinterpret_cast<char const*>(data + midpoint),
63
354
                       size - midpoint);
64
65
354
    cmCMakePath path1(input1);
66
354
    cmCMakePath path2(input2);
67
68
    // Append operations
69
354
    cmCMakePath appended = path1 / path2;
70
354
    (void)appended.String();
71
72
    // Comparison
73
354
    (void)(path1 == path2);
74
354
  }
75
76
357
  return 0;
77
376
}