Skip to content

Commit 9dad794

Browse files
committed
bug detectors: fix error stack and the error message of the finding
- remove internal libraries from the stack trace of the finding - add tests for double-printed finding messages
1 parent 41c54c3 commit 9dad794

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

packages/core/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ function cleanErrorStack(error: Error): string {
335335
if (index !== undefined && index >= 0) {
336336
error.stack = stack.slice(index + 1).join("\n");
337337
}
338+
339+
// also delete all lines that mention "jazzer.js/packages/"
340+
error.stack = error.stack.replace(/.*jazzer.js\/packages\/.*\n/g, "");
338341
}
339342

340343
const result: string[] = [];

packages/jest-runner/worker.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,6 @@ export class JazzerWorker {
212212
// Mark fuzzer tests as skipped and not as error.
213213
if (error instanceof FuzzerStartError) {
214214
skipTest = true;
215-
} else if (error instanceof Finding) {
216-
// Add error message to the top of the stack trace---Jest will print it at the top.
217-
error.stack = error.message + "\n" + error.stack;
218215
}
219216
errors.push(error);
220217
});

tests/bug-detectors/bug-detectors.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ describe("General tests", () => {
3030
const bugDetectorDirectory = path.join(__dirname, "general");
3131
const friendlyFilePath = path.join(bugDetectorDirectory, "FRIENDLY");
3232
const evilFilePath = path.join(bugDetectorDirectory, "jaz_zer");
33+
const errorPattern =
34+
/Command Injection in execSync\(\): called with 'jaz_zer'/g;
35+
36+
function expectErrorToBePrintedOnce(output) {
37+
const matches = output.match(errorPattern);
38+
expect(matches).toBeTruthy();
39+
expect(matches.length).toBe(1);
40+
}
3341

3442
// Delete files created by the tests.
3543
beforeEach(() => {
@@ -48,6 +56,8 @@ describe("General tests", () => {
4856
fuzzTest.execute();
4957
}).toThrow(FuzzingExitCode);
5058
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
59+
// check that the stdout has the following line only once: "Command Injection in execSync(): called with 'jaz_zer'"
60+
expectErrorToBePrintedOnce(fuzzTest.stdout);
5161
});
5262

5363
it("Call with EVIL string; SYNC", () => {
@@ -60,6 +70,7 @@ describe("General tests", () => {
6070
fuzzTest.execute();
6171
}).toThrow(FuzzingExitCode);
6272
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
73+
expectErrorToBePrintedOnce(fuzzTest.stdout);
6374
});
6475

6576
it("Call with FRIENDLY string; ASYNC", () => {
@@ -92,6 +103,7 @@ describe("General tests", () => {
92103
fuzzTest.execute();
93104
}).toThrow(FuzzingExitCode);
94105
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
106+
expectErrorToBePrintedOnce(fuzzTest.stdout);
95107
});
96108

97109
it("Call with EVIL string; With done callback; With try/catch", () => {
@@ -104,6 +116,7 @@ describe("General tests", () => {
104116
fuzzTest.execute();
105117
}).toThrow(FuzzingExitCode);
106118
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
119+
expectErrorToBePrintedOnce(fuzzTest.stdout);
107120
});
108121

109122
it("Call with EVIL string; With done callback; With timeout", () => {
@@ -192,7 +205,7 @@ describe("General tests", () => {
192205
.sync(false)
193206
.fuzzEntryPoint("ForkModeCallOriginalEvilAsync")
194207
.dir(bugDetectorDirectory)
195-
.runs(200)
208+
.runs(10)
196209
.forkMode(3)
197210
.build();
198211
fuzzTest.execute();
@@ -242,6 +255,7 @@ describe("General tests", () => {
242255
fuzzTest.execute();
243256
}).toThrow(JestRegressionExitCode);
244257
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
258+
expectErrorToBePrintedOnce(fuzzTest.stderr);
245259
});
246260

247261
it("Jest: Test with EVIL command; ASYNC", () => {
@@ -257,6 +271,7 @@ describe("General tests", () => {
257271
fuzzTest.execute();
258272
}).toThrow(JestRegressionExitCode);
259273
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
274+
expectErrorToBePrintedOnce(fuzzTest.stderr);
260275
});
261276

262277
it("Jest: Test with FRIENDLY command", () => {
@@ -300,6 +315,7 @@ describe("General tests", () => {
300315
process.platform === "win32" ? JestRegressionExitCode : FuzzingExitCode
301316
);
302317
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
318+
expectErrorToBePrintedOnce(fuzzTest.stderr);
303319
});
304320

305321
it("Jest: Fuzzing mode; Test with FRIENDLY command", () => {
@@ -330,6 +346,7 @@ describe("General tests", () => {
330346
fuzzTest.execute();
331347
}).toThrow(JestRegressionExitCode);
332348
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
349+
expectErrorToBePrintedOnce(fuzzTest.stderr);
333350
});
334351

335352
it("Jest: Test with FRIENDLY command; Done callback", () => {

0 commit comments

Comments
 (0)