From dc28e4a24ab7fddd459b40da3953cceec8e691dc Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Fri, 20 Jan 2017 20:37:00 +0000 Subject: [PATCH] Updated Fuzzing your nim code to rabbit out all the hard bugs (markdown) --- ...im-code-to-rabbit-out-all-the-hard-bugs.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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. + + + + +