diff --git a/Fuzzing-your-nim-code-to-rabbit-out-all-the-hard-bugs.md b/Fuzzing-your-nim-code-to-rabbit-out-all-the-hard-bugs.md index ada9bf2..14bc90a 100644 --- a/Fuzzing-your-nim-code-to-rabbit-out-all-the-hard-bugs.md +++ b/Fuzzing-your-nim-code-to-rabbit-out-all-the-hard-bugs.md @@ -127,3 +127,26 @@ You can limit the exceptions that are considered crashes by adjusting the except Then I'd strongly suggest to start reading up on afl if you want to employ it with confidence. +## Testing for bugs in your code + +By default AFL will identify segfaults and such but not vulnerabilities in your code. You can add extra assertions to be run only during the AFL test with: + +```nim +when defined(macosx) or defined(linux) or defined(freebsd) or + defined(openbsd) or defined(netbsd) or defined(solaris): + import posix + +template AFLAssert*(cond: bool) = + when defined(afl): + if not cond: + echo "Failed AFL assertion: " & astToStr(cond) + let pid = posix.getpid() + discard posix.kill(pid, posix.SIGABRT) +``` + +Also add `-d:afl` to your nim.cfg to enable this. + + + + +