This commit is contained in:
Antonis Geralis 2022-09-15 01:42:30 +03:00
parent 6168907b03
commit 0e0442d2b1
1 changed files with 6 additions and 6 deletions

View File

@ -28,15 +28,15 @@ proc fuzzMe(s: string, a, b, c: int32) =
if a == 0xdeadc0de'i32 and b == 0x11111111'i32 and c == 0x22222222'i32: if a == 0xdeadc0de'i32 and b == 0x11111111'i32 and c == 0x22222222'i32:
if s.len == 100: doAssert false if s.len == 100: doAssert false
func fuzzTarget(data: (string, int32, int32, int32)) = proc fuzzTarget(data: (string, int32, int32, int32)) =
let (s, a, b, c) = data let (s, a, b, c) = data
fuzzMe(s, a, b, c) fuzzMe(s, a, b, c)
defaultMutator(fuzzTarget) defaultMutator(fuzzTarget)
``` ```
> **WARNING**: Fuzz targets must not modify the input variable. This can be ensured by using `.noSideEffect` > **WARNING**: Fuzz targets must not modify the input variable. This can be ensured for `ref`
> and {.experimental: "strictFuncs".} > pointers by using the `func` keyword and {.experimental: "strictFuncs".}
Or complex as shown bellow: Or complex as shown bellow:
@ -52,14 +52,14 @@ type
of Br: discard of Br: discard
of Text: textStr: string of Text: textStr: string
func `==`(a, b: ContentNode): bool = proc `==`(a, b: ContentNode): bool =
if a.kind != b.kind: return false if a.kind != b.kind: return false
case a.kind case a.kind
of P: return a.pChildren == b.pChildren of P: return a.pChildren == b.pChildren
of Br: return true of Br: return true
of Text: return a.textStr == b.textStr of Text: return a.textStr == b.textStr
func fuzzTarget(x: ContentNode) = proc fuzzTarget(x: ContentNode) =
# Convert or translate `x` to any format (JSON, HMTL, binary, etc...) # Convert or translate `x` to any format (JSON, HMTL, binary, etc...)
# and feed it to the API you are testing. # and feed it to the API you are testing.
@ -101,7 +101,7 @@ control of the mutation procedure, like uncompressing a `seq[byte]` then calling
`runMutator` on the raw data and compressing the output again. `runMutator` on the raw data and compressing the output again.
```nim ```nim
func myTarget(x: seq[byte]) = proc myTarget(x: seq[byte]) =
var data = uncompress(x) var data = uncompress(x)
... ...