Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 5ff8bef

Browse files
author
Yevgeny Pats
committed
Added versifier algorithm
1 parent 3a3d80a commit 5ff8bef

File tree

6 files changed

+1010
-8
lines changed

6 files changed

+1010
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Features of the fuzz target:
2828

2929
* Jsfuzz will call the fuzz target in an infinite loop with random data (according to the coverage guided algorithm) passed to `buf`( in a separate process).
3030
* The function must catch and ignore any expected exceptions that arise when passing invalid input to the tested package.
31-
* The fuzz target must call the test function/library with wither the passed buffer or a transformation on the test buffer
31+
* The fuzz target must call the test function/library with with the passed buffer or a transformation on the test buffer
3232
if the structure is different or from different type.
3333
* Fuzz functions can also implement application level checks to catch application/logical bugs - For example:
3434
decode the buffer with the testable library, encode it again, and check that both results are equal. To communicate the results

package-lock.json

Lines changed: 71 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsfuzz",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Coverage Guided Javascript Fuzzer",
55
"main": "build/src/index.js",
66
"types": "build/src/inde.d.ts",
@@ -20,6 +20,7 @@
2020
"@types/esprima": "^4.0.2",
2121
"@types/estraverse": "^0.0.6",
2222
"@types/estree": "^0.0.39",
23+
"deep-equal": "^1.1.0",
2324
"escodegen": "^1.12.0",
2425
"esprima": "^4.0.1",
2526
"estraverse": "^4.3.0",

src/fuzzer.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Corpus} from "./corpus";
33
import * as fs from "fs";
44
import {ChildProcess, fork} from "child_process";
55
import {ManageMessageType, WorkerMessage, WorkerMessageType} from "./protocol";
6+
import {BuildVerse, Verse} from "./versifier";
67

78
const crypto = require('crypto');
89
const util = require('util');
@@ -26,15 +27,20 @@ export class Fuzzer {
2627
private lastSampleTime: number;
2728
private executionsInSample: number;
2829
private regression: boolean;
30+
private verse: Verse | null;
31+
private readonly versifier: boolean;
2932

3033
constructor(target: string,
3134
dir: string[],
3235
exactArtifactPath: string,
3336
rssLimitMb: number,
3437
timeout: number,
35-
regression: boolean) {
38+
regression: boolean,
39+
versifier: boolean) {
3640
this.target = target;
3741
this.corpus = new Corpus(dir);
42+
this.versifier = versifier;
43+
this.verse = null;
3844
this.total_executions = 0;
3945
this.total_coverage = 0;
4046
this.exactArtifactPath = exactArtifactPath;
@@ -110,14 +116,22 @@ export class Fuzzer {
110116
} else if (m.coverage > this.total_coverage) {
111117
this.total_coverage = m.coverage;
112118
this.logStats('NEW');
113-
this.corpus.putBuffer(buf)
119+
this.corpus.putBuffer(buf);
120+
if (buf.length > 0 && this.versifier) {
121+
this.verse = BuildVerse(this.verse, buf);
122+
}
114123
} else if ((diffOneSample/1000) > this.timeout) {
115124
console.log("=================================================================");
116125
console.log(`timeout reached. testcase took: ${diffOneSample}`);
117126
this.worker.kill('SIGKILL');
118127
return;
119128
}
120-
buf = this.corpus.generateInput();
129+
if (this.total_executions % 10 != 0 || this.verse === null || !this.versifier) {
130+
buf = this.corpus.generateInput();
131+
} else {
132+
buf = this.verse.Rhyme();
133+
}
134+
121135
this.worker.send({
122136
type: ManageMessageType.WORK,
123137
buf: buf

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import {Fuzzer} from './fuzzer';
33
import yargs from 'yargs';
44

55
function startFuzzer(argv: any) {
6-
// @ts-ignore
76
const fuzzer = new Fuzzer(
87
argv.target,
98
argv.dir,
109
argv.exactArtifactPath,
1110
argv.rssLimitMb,
12-
argv.timeout);
11+
argv.timeout,
12+
argv.regression,
13+
argv.versifier);
1314
fuzzer.start()
1415
}
1516

@@ -50,5 +51,10 @@ require('yargs')
5051
default: false,
5152
hidden: true
5253
})
54+
.option('versifier', {
55+
type: 'boolean',
56+
description: 'use versifier algorithm (good for text based protocols)',
57+
default: true,
58+
})
5359
.help()
5460
.argv;

0 commit comments

Comments
 (0)