Apple,  Swift

Simple Swift Fuzzer

Sometimes we want to test a function to see how… robust it is. This is a small example fuzzing function to input randomly generated characters that get passed to another function. It just uses randomBytes so much more logic could easily be added to constrain what’s being passed to whatever type it’s being passed to… but this satisfies my need.

import Foundation

func fuzz(function: () -> Void) {
// Generate a random input to pass to the function we are fuzzing
let input = Data(randomBytes: 1024)

// Call the fuzzed function with the random input
do {
try function()
} catch {
print(error)
}

// Check the fuzzed function to see if it crashed
if ProcessInfo.processInfo.isCrashed {
print("The function crashed")
}
}