Skip to content

Commit 8e9b130

Browse files
committed
core: Print finding stack trace before libFuzzer details
1 parent a341ea5 commit 8e9b130

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

packages/core/core.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ function reportFuzzingResult(
252252
console.error(`INFO: Received expected error "${name}".`);
253253
return new FuzzingResult(FuzzingExitCode.Ok, error);
254254
} else {
255-
printFinding(error);
256255
console.error(
257256
`ERROR: Received error "${name}" is not in expected errors [${expectedErrors}].`,
258257
);
@@ -269,7 +268,6 @@ function reportFuzzingResult(
269268
}
270269

271270
// Error found, but no specific one expected.
272-
printFinding(error);
273271
return new FuzzingResult(FuzzingExitCode.Finding, error);
274272
}
275273

@@ -316,13 +314,25 @@ export function asFindingAwareFuzzFn(
316314
originalFuzzFn: fuzzer.FuzzTarget,
317315
dumpCrashingInput = true,
318316
): FindingAwareFuzzTarget {
317+
function printAndDump(error: unknown): void {
318+
cleanErrorStack(error);
319+
if (
320+
!(
321+
error instanceof FuzzerSignalFinding &&
322+
error.exitCode === FuzzingExitCode.Ok
323+
)
324+
) {
325+
printFinding(error);
326+
if (dumpCrashingInput) {
327+
fuzzer.fuzzer.printAndDumpCrashingInput();
328+
}
329+
}
330+
}
331+
319332
function throwIfError(fuzzTargetError?: unknown): undefined | never {
320333
const error = clearFirstFinding() ?? fuzzTargetError;
321334
if (error) {
322-
cleanErrorStack(error);
323-
if (dumpCrashingInput) {
324-
printAndDumpCrashingInput(error);
325-
}
335+
printAndDump(error);
326336
throw error;
327337
}
328338
}
@@ -372,9 +382,8 @@ export function asFindingAwareFuzzFn(
372382
// Return result of fuzz target to enable sanity checks in C++ part.
373383
const result = originalFuzzFn(data, (err?) => {
374384
const error = clearFirstFinding() ?? err;
375-
cleanErrorStack(error);
376-
if (error && dumpCrashingInput) {
377-
printAndDumpCrashingInput(error);
385+
if (error) {
386+
printAndDump(error);
378387
}
379388
callbacks.runAfterEachCallbacks();
380389
done(error);
@@ -391,15 +400,6 @@ export function asFindingAwareFuzzFn(
391400
}
392401
}
393402

394-
function printAndDumpCrashingInput(error: unknown) {
395-
if (
396-
!(error instanceof FuzzerSignalFinding) ||
397-
error.exitCode !== FuzzingExitCode.Ok
398-
) {
399-
fuzzer.fuzzer.printAndDumpCrashingInput();
400-
}
401-
}
402-
403403
// Export public API from within core module for easy access.
404404
export * from "./api";
405405
export { FuzzedDataProvider } from "./FuzzedDataProvider";

0 commit comments

Comments
 (0)