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

Commit

Permalink
Merge pull request #17 from swapgs/feature/only-ascii
Browse files Browse the repository at this point in the history
Add support for --only-ascii
  • Loading branch information
Yevgeny Pats authored Nov 21, 2019
2 parents cb50804 + 21b82ec commit b1f3af8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export class Corpus {
private corpusPath: string | undefined;
private maxInputSize: number;
private seedLength: number;
private readonly onlyAscii: boolean;

constructor(dir: string[]) {
constructor(dir: string[], onlyAscii: boolean) {
this.inputs = [];
this.onlyAscii = onlyAscii;
this.maxInputSize = 4096;
for (let i of dir) {
if (!fs.existsSync(i)) {
Expand Down Expand Up @@ -107,6 +109,16 @@ export class Corpus {
}
}

toAscii(buf: Buffer) {
let x;
for (let i = 0; i < buf.length; i++) {
x = buf[i] & 127;
if ((x < 0x20 || x > 0x7E) && x !== 0x09 && (x < 0xA || x > 0xD)) {
buf[i] = 0x20;
}
}
}

mutate(buf: Buffer) {
let res = Buffer.allocUnsafe(buf.length);
buf.copy(res, 0, 0, buf.length);
Expand Down Expand Up @@ -342,6 +354,11 @@ export class Corpus {
if (res.length > this.maxInputSize) {
res = res.slice(0, this.maxInputSize)
}

if (this.onlyAscii) {
this.toAscii(res);
}

return res;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/fuzzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ export class Fuzzer {
private regression: boolean;
private verse: Verse | null;
private readonly versifier: boolean;
private readonly onlyAscii: boolean;

constructor(target: string,
dir: string[],
exactArtifactPath: string,
rssLimitMb: number,
timeout: number,
regression: boolean,
onlyAscii: boolean,
versifier: boolean) {
this.target = target;
this.corpus = new Corpus(dir);
this.corpus = new Corpus(dir, onlyAscii);
this.onlyAscii = onlyAscii;
this.versifier = versifier;
this.verse = null;
this.total_executions = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function startFuzzer(argv: any) {
argv.rssLimitMb,
argv.timeout,
argv.regression,
argv.onlyAscii,
argv.versifier);
fuzzer.start()
}
Expand Down Expand Up @@ -56,5 +57,10 @@ require('yargs')
description: 'use versifier algorithm (good for text based protocols)',
default: true,
})
.option('only-ascii', {
type: 'boolean',
description: 'generate only ASCII (isprint+isspace) inputs',
default: false,
})
.help()
.argv;

0 comments on commit b1f3af8

Please sign in to comment.