Class AFLGuidance
- All Implemented Interfaces:
Guidance
- Direct Known Subclasses:
PerfFuzzGuidance
An instance of this class actually communicates with a proxy that sits between AFL and JQF. The proxy is the target program launched by AFL; it passes messages back and forth between AFL and JQF and helps populate the shared memory coverage buffer that the JVM cannot access.
- Author:
- Rohan Padhye and Caroline Lemieux
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intThe size of the "coverage" map that will be sent to AFL.protected booleanWhether to keep executing more inputs.protected ByteBufferThe bits that will be communicated to the AFL proxy.protected FileThe file in which AFL will write its input.protected final InputStreamThe communication channel from AFL proxy to us.protected final OutputStreamThe communication channel from us to the AFL proxy.protected byte[]The "coverage" map that will be sent to AFL. -
Constructor Summary
ConstructorsConstructorDescriptionAFLGuidance(File inputFile, File inPipe, File outPipe) Creates an instance of an AFLGuidance given file handles for I/O.AFLGuidance(String inputFileName, String inPipeName, String outPipeName) Creates an instance of an AFLGuidance given file names for I/O. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidClears the feedback buffer by resetting it to zero.voidfinalize()Closes the pipes used to communicate with the AFL proxy.generateCallBack(Thread thread) Returns a callback to handle trace events.getInput()Returns an input stream containing the bytes that AFL has written to.protected voidRecords branch coverage by snooping on branch events and incrementing the branch-specific counter in the tracebits map.voidhandleResult(Result result, Throwable error) Notifies the AFL proxy that a run has completed and whether it was a success.booleanhasInput()Waits for the AFL proxy to send a ready signal.protected voidincrementTraceBits(int index) Increments the 8-bit counter at given index.This method is only invoked during optional observability logging to provide the type of guidance used for input generation.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.berkeley.cs.jqf.fuzz.guidance.Guidance
beforeRun, observeGeneratedArgs
-
Field Details
-
inputFile
The file in which AFL will write its input. -
proxyInput
The communication channel from AFL proxy to us. -
proxyOutput
The communication channel from us to the AFL proxy. -
COVERAGE_MAP_SIZE
protected static final int COVERAGE_MAP_SIZEThe size of the "coverage" map that will be sent to AFL.- See Also:
-
traceBits
protected byte[] traceBitsThe "coverage" map that will be sent to AFL. -
everything_ok
protected boolean everything_okWhether to keep executing more inputs. -
feedback
The bits that will be communicated to the AFL proxy.
-
-
Constructor Details
-
AFLGuidance
Creates an instance of an AFLGuidance given file handles for I/O.- Parameters:
inputFile- the file that AFL will write inputs toinPipe- a FIFO-like pipe for receiving messages from the AFL proxyoutPipe- a FIFO-like pipe for sending messages to the AFL proxy- Throws:
IOException- if any file or pipe could not be opened
-
AFLGuidance
Creates an instance of an AFLGuidance given file names for I/O.- Parameters:
inputFileName- the file that AFL will write inputs toinPipeName- a FIFO-like pipe for receiving messages from the AFL proxyoutPipeName- a FIFO-like pipe for sending messages to the AFL proxy- Throws:
IOException- if any file or pipe could not be opened
-
-
Method Details
-
finalize
public void finalize()Closes the pipes used to communicate with the AFL proxy. -
observeGuidance
Description copied from interface:GuidanceThis method is only invoked during optional observability logging to provide the type of guidance used for input generation.
- Specified by:
observeGuidancein interfaceGuidance
-
getInput
Returns an input stream containing the bytes that AFL has written to.- Specified by:
getInputin interfaceGuidance- Returns:
- a stream of bytes to be used by the input generator(s)
- Throws:
IllegalStateException- if the lasthasInput()returnedfalseGuidanceException- if there was an I/O error when opening the file
-
hasInput
public boolean hasInput()Waits for the AFL proxy to send a ready signal. -
handleResult
Notifies the AFL proxy that a run has completed and whether it was a success. 1This method also sends coverage information back to the AFL proxy, which is responsible for updating the shared memory region used by afl-fuzz.
If the trial resulted in an assumption violation, we do not mark it is a crash, but we also do not send any coverage feedback so that AFL does not consider the last input interesting enough to keep in its queue.
- Specified by:
handleResultin interfaceGuidance- Parameters:
result- the result of the fuzzing trialerror- the exception thrown by the test, ornull
-
generateCallBack
Returns a callback to handle trace events.The call back is the same for all threads. This guidance does not use any synchronization and hence the feedback is not guaranteed to be reliable when multiple threads are used.
- Specified by:
generateCallBackin interfaceGuidance- Parameters:
thread- the thread whose events to handle- Returns:
- a callback to handle trace events
-
handleEvent
Records branch coverage by snooping on branch events and incrementing the branch-specific counter in the tracebits map.- Parameters:
e- the trace event to handle
-
incrementTraceBits
protected void incrementTraceBits(int index) Increments the 8-bit counter at given index.Overflows are possible but ignored (as in AFL).
- Parameters:
index- the key in the trace bits map
-
clearFeedbackBuffer
protected void clearFeedbackBuffer()Clears the feedback buffer by resetting it to zero. -
checkForTimeouts
- Throws:
TimeoutException
-