MCPcopy Create free account
hub / github.com/HexHive/NASS / main

Function main

fuzz/libfuzzer/dataflow/DataFlow.cpp:156–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156int main(int argc, char **argv) {
157 if (LLVMFuzzerInitialize)
158 LLVMFuzzerInitialize(&argc, &argv);
159 if (argc == 1)
160 return PrintFunctions();
161 assert(argc == 2 || argc == 3);
162
163 const char *Input = argv[1];
164 fprintf(stderr, "INFO: reading '%s'\n", Input);
165 FILE *In = fopen(Input, "r");
166 assert(In);
167 fseek(In, 0, SEEK_END);
168 InputLen = ftell(In);
169 fseek(In, 0, SEEK_SET);
170 unsigned char *Buf = (unsigned char*)malloc(InputLen);
171 size_t NumBytesRead = fread(Buf, 1, InputLen, In);
172 assert(NumBytesRead == InputLen);
173 fclose(In);
174
175 NumIterations = (NumBytesRead + kNumLabels - 1) / kNumLabels;
176 FuncLabelsPerIter =
177 (dfsan_label **)calloc(NumIterations, sizeof(dfsan_label *));
178 for (size_t Iter = 0; Iter < NumIterations; Iter++)
179 FuncLabelsPerIter[Iter] =
180 (dfsan_label *)calloc(__dft.NumFuncs, sizeof(dfsan_label));
181
182 for (size_t Iter = 0; Iter < NumIterations; Iter++) {
183 fprintf(stderr, "INFO: running '%s' %zd/%zd\n", Input, Iter, NumIterations);
184 dfsan_flush();
185 dfsan_set_label(0, Buf, InputLen);
186 __dft.FuncLabels = FuncLabelsPerIter[Iter];
187
188 size_t BaseIdx = Iter * kNumLabels;
189 size_t LastIdx = BaseIdx + kNumLabels < NumBytesRead ? BaseIdx + kNumLabels
190 : NumBytesRead;
191 assert(BaseIdx < LastIdx);
192 for (size_t Idx = BaseIdx; Idx < LastIdx; Idx++)
193 dfsan_set_label(1 << (Idx - BaseIdx), Buf + Idx, 1);
194 LLVMFuzzerTestOneInput(Buf, InputLen);
195 }
196 free(Buf);
197
198 bool OutIsStdout = argc == 2;
199 fprintf(stderr, "INFO: writing dataflow to %s\n",
200 OutIsStdout ? "<stdout>" : argv[2]);
201 FILE *Out = OutIsStdout ? stdout : fopen(argv[2], "w");
202 PrintDataFlow(Out);
203 PrintCoverage(Out);
204 if (!OutIsStdout) fclose(Out);
205}

Callers

nothing calls this directly

Calls 5

LLVMFuzzerInitializeFunction · 0.85
PrintFunctionsFunction · 0.85
PrintDataFlowFunction · 0.85
PrintCoverageFunction · 0.85
LLVMFuzzerTestOneInputFunction · 0.50

Tested by

no test coverage detected