MCPcopy Create free account
hub / github.com/Kitware/CMake / LLVMFuzzerTestOneInput

Function LLVMFuzzerTestOneInput

Tests/Fuzzing/cmScriptFuzzer.cxx:91–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
92{
93 if (size == 0 || size > kMaxInputSize) {
94 return 0;
95 }
96
97#ifdef __linux__
98 if (g_useMemfd) {
99 // Extract fd from path and write directly
100 int fd = std::atoi(g_scriptFile.c_str() + 14); // "/proc/self/fd/"
101 ftruncate(fd, 0);
102 lseek(fd, 0, SEEK_SET);
103 if (write(fd, data, size) != static_cast<ssize_t>(size)) {
104 return 0;
105 }
106 } else
107#endif
108 {
109 // Write script to temp file
110 FILE* fp = fopen(g_scriptFile.c_str(), "wb");
111 if (!fp)
112 return 0;
113 fwrite(data, 1, size, fp);
114 fclose(fp);
115 }
116
117 // Save CWD in case script uses file(CHDIR)
118 std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
119
120 // Create cmake instance for script mode
121 cmake cm(cmState::Role::Script);
122 cm.SetHomeDirectory(g_testDir);
123 cm.SetHomeOutputDirectory(g_testDir);
124
125 // Run the script
126 std::vector<std::string> args;
127 args.push_back("cmake");
128 args.push_back("-P");
129 args.push_back(g_scriptFile);
130
131 (void)cm.Run(args, false);
132
133 // Restore CWD before cleanup (script may have changed it via file(CHDIR))
134 cmSystemTools::ChangeDirectory(cwd);
135
136 // Cleanup temp file (memfd doesn't need cleanup)
137 if (!g_useMemfd) {
138 unlink(g_scriptFile.c_str());
139 }
140
141 // Clean up any files the script may have created in g_testDir
142 // This prevents disk growth and non-determinism from previous iterations
143 cmSystemTools::RemoveADirectory(g_testDir);
144 cmSystemTools::MakeDirectory(g_testDir);
145
146 return 0;
147}

Callers

nothing calls this directly

Calls 6

writeFunction · 0.85
c_strMethod · 0.80
SetHomeDirectoryMethod · 0.80
push_backMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…