From 035b7eda242c6844f14bcb1504a610322898e9a0 Mon Sep 17 00:00:00 2001 From: kdeme Date: Tue, 1 Oct 2019 12:00:20 +0200 Subject: [PATCH] Adress review feedback --- tests/fuzzing/fuzz_helpers.nim | 10 +++++----- tests/fuzzing/fuzztest.nim | 13 +++---------- tests/fuzzing/rlp/fuzz.nim | 2 +- tests/p2p/p2p_test_helper.nim | 7 ++++--- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/tests/fuzzing/fuzz_helpers.nim b/tests/fuzzing/fuzz_helpers.nim index 8af34f7..66ed342 100644 --- a/tests/fuzzing/fuzz_helpers.nim +++ b/tests/fuzzing/fuzz_helpers.nim @@ -44,7 +44,7 @@ type proc aflCompile*(target: string, c: Compiler) = let aflOptions = &"-d:standalone -d:noSignalHandler {$c}" - let compileCmd = &"nim c {defaultFlags} {aflOptions} {target}" + let compileCmd = &"""nim c {defaultFlags} {aflOptions} {target}""" exec compileCmd proc aflExec*(target: string, inputDir: string, resultsDir: string, @@ -57,14 +57,14 @@ proc aflExec*(target: string, inputDir: string, resultsDir: string, var fuzzCmd: string # if there is an output dir already, continue fuzzing from previous run if (not dirExists(resultsDir)) or cleanStart: - fuzzCmd = &"afl-fuzz -i {inputDir} -o {resultsDir} -M fuzzer01 -- ./{target}" + fuzzCmd = &"""afl-fuzz -i {inputDir} -o {resultsDir} -M fuzzer01 -- ./{target}""" else: - fuzzCmd = &"afl-fuzz -i - -o {resultsDir} -M fuzzer01 -- ./{target}" + fuzzCmd = &"""afl-fuzz -i - -o {resultsDir} -M fuzzer01 -- ./{target}""" exec fuzzCmd proc libFuzzerCompile*(target: string) = let libFuzzerOptions = &"--noMain {libFuzzerClang}" - let compileCmd = &"nim c {defaultFlags} {libFuzzerOptions} {target}" + let compileCmd = &"""nim c {defaultFlags} {libFuzzerOptions} {target}""" exec compileCmd proc libFuzzerExec*(target: string, corpusDir: string) = @@ -72,7 +72,7 @@ proc libFuzzerExec*(target: string, corpusDir: string) = # libFuzzer is OK when starting with empty corpus dir mkDir(corpusDir) - exec &"./{target} {corpusDir}" + exec &"""./{target} {corpusDir}""" proc getDir*(path: string): string = # TODO: This is not platform friendly at all. diff --git a/tests/fuzzing/fuzztest.nim b/tests/fuzzing/fuzztest.nim index a0f2ba4..a8efeed 100644 --- a/tests/fuzzing/fuzztest.nim +++ b/tests/fuzzing/fuzztest.nim @@ -1,4 +1,4 @@ -import streams, posix, strutils, chronicles, macros +import streams, posix, strutils, chronicles, macros, stew/ranges/ptr_arith template fuzz(body) = # For code we want to fuzz, SIGSEGV is needed on unwanted exceptions. @@ -27,9 +27,6 @@ proc readStdin*(): seq[byte] = proc NimMain() {.importc: "NimMain".} -template `+`*[T](p: ptr T, off: int): ptr T = - cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[])) - template test*(body: untyped): untyped = when defined(standalone): var payload {.inject.} = readStdin() @@ -38,12 +35,8 @@ template test*(body: untyped): untyped = else: proc fuzzerCall(data: ptr byte, len: csize): cint {.exportc: "LLVMFuzzerTestOneInput".} = - var payload {.inject.} : seq[byte] - if len > 0: - # TODO: something better to get this data in the seq? - newSeq(payload, len) - for i in 0..