Adress review feedback

This commit is contained in:
kdeme 2019-10-01 12:00:20 +02:00 committed by zah
parent 91862ce65b
commit 035b7eda24
4 changed files with 13 additions and 19 deletions

View File

@ -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.

View File

@ -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..<len:
payload[i] = (data + i)[]
template payload(): auto =
makeOpenArray(data, len)
`body`

View File

@ -6,7 +6,7 @@ init:
test:
try:
var rlp = rlpFromBytes(payload.toRange)
var rlp = rlpFromBytes(@payload.toRange)
discard rlp.inspect()
except RlpError:
debug "Inspect failed", err = getCurrentExceptionMsg()

View File

@ -33,8 +33,9 @@ template asyncTest*(name, body: untyped) =
proc scenario {.async.} = body
waitFor scenario()
proc packData*(payload: seq[byte], pk: PrivateKey): seq[byte] =
proc packData*(payload: openArray[byte], pk: PrivateKey): seq[byte] =
let
payloadSeq = @payload
signature = @(pk.signMessage(payload).getRaw())
msgHash = keccak256.digest(signature & payload)
result = @(msgHash.data) & signature & payload
msgHash = keccak256.digest(signature & payloadSeq)
result = @(msgHash.data) & signature & payloadSeq