VirtualBox

source: vbox/trunk/include/iprt/fuzz.h@ 77577

Last change on this file since 77577 was 77544, checked in by vboxsync, 6 years ago

Runtime/fuzz: Updates, add a target state recording mechanism to record changes in target behavior caused by mutated inputs. This allows to decide which mutated input gets added to the input corpus and which one gets discarded. Currently this is only able to record the stdout/stderr channels of the fuzzed process but other sources to detect changed behvior will get added in the future

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.5 KB
Line 
1/** @file
2 * IPRT - Fuzzing framework
3 */
4
5/*
6 * Copyright (C) 2018-2019 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_fuzz_h
27#define IPRT_INCLUDED_fuzz_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33#include <iprt/types.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_rt_fuzz RTFuzz - Data fuzzing framework
38 * @ingroup grp_rt
39 * @sa grp_rt_test
40 * @{
41 */
42
43/** A fuzzer context handle. */
44typedef struct RTFUZZCTXINT *RTFUZZCTX;
45/** Pointer to a fuzzer context handle. */
46typedef RTFUZZCTX *PRTFUZZCTX;
47/** NIL fuzzer context handle. */
48#define NIL_RTFUZZCTX ((RTFUZZCTX)~(uintptr_t)0)
49/** A fuzzer input handle. */
50typedef struct RTFUZZINPUTINT *RTFUZZINPUT;
51/** Pointer to a fuzzer input handle. */
52typedef RTFUZZINPUT *PRTFUZZINPUT;
53/** NIL fuzzer input handle. */
54#define NIL_RTFUZZINPUT ((RTFUZZINPUT)~(uintptr_t)0)
55
56
57/** A fuzzer target recorder handler. */
58typedef struct RTFUZZTGTRECINT *RTFUZZTGTREC;
59/** Pointer to a fuzzer target recorder handle. */
60typedef RTFUZZTGTREC *PRTFUZZTGTREC;
61/** NIL fuzzer target recorder handle. */
62#define NIL_RTFUZZTGTREC ((RTFUZZTGTREC)~(uintptr_t)0)
63/** A fuzzed target state handle. */
64typedef struct RTFUZZTGTSTATEINT *RTFUZZTGTSTATE;
65/** Pointer to a fuzzed target state handle. */
66typedef RTFUZZTGTSTATE *PRTFUZZTGTSTATE;
67/** NIL fuzzed target state handle. */
68#define NIL_RTFUZZTGTSTATE ((RTFUZZTGTSTATE)~(uintptr_t)0)
69
70
71/** Fuzzing observer handle. */
72typedef struct RTFUZZOBSINT *RTFUZZOBS;
73/** Pointer to a fuzzing observer handle. */
74typedef RTFUZZOBS *PRTFUZZOBS;
75/** NIL fuzzing observer handle. */
76#define NIL_RTFUZZOBS ((RTFUZZOBS)~(uintptr_t)0)
77
78
79/**
80 * Fuzzing context type.
81 */
82typedef enum RTFUZZCTXTYPE
83{
84 /** Invalid type. */
85 RTFUZZCTXTYPE_INVALID = 0,
86 /** Original input data is a single binary large object (BLOB), from a file or similar. */
87 RTFUZZCTXTYPE_BLOB,
88 /** Original input data is from a data stream like a network connection. */
89 RTFUZZCTXTYPE_STREAM,
90 /** 32bit hack. */
91 RTFUZZCTXTYPE_32BIT_HACK = 0x7fffffff
92} RTFUZZCTXTYPE;
93
94
95/** @name RTFUZZCTX_F_XXX - Flags for RTFuzzCtxCfgSetBehavioralFlags
96 * @{ */
97/** Adds all generated inputs automatically to the input corpus for the owning context. */
98#define RTFUZZCTX_F_BEHAVIORAL_ADD_INPUT_AUTOMATICALLY_TO_CORPUS RT_BIT_32(0)
99/** All valid behavioral modification flags. */
100#define RTFUZZCTX_F_BEHAVIORAL_VALID (RTFUZZCTX_F_BEHAVIORAL_ADD_INPUT_AUTOMATICALLY_TO_CORPUS)
101/** @} */
102
103
104/**
105 * Fuzzing context state export callback.
106 *
107 * @returns IPRT status code.
108 * @param hFuzzCtx Handle of the fuzzing context.
109 * @param pvBuf The data to write.
110 * @param cbWrite Number of bytes to write.
111 * @param pvUser Opaque user data passed in RTFuzzCtxStateExport().
112 */
113typedef DECLCALLBACK(int) FNRTFUZZCTXEXPORT(RTFUZZCTX hFuzzCtx, const void *pvBuf, size_t cbWrite, void *pvUser);
114/** Pointer to a fuzzing context state export callback. */
115typedef FNRTFUZZCTXEXPORT *PFNRTFUZZCTXEXPORT;
116
117/**
118 * Fuzzing context state import callback.
119 *
120 * @returns IPRT status code.
121 * @param hFuzzCtx Handle of the fuzzing context.
122 * @param pvBuf Where to store the read data.
123 * @param cbRead Number of bytes to read.
124 * @param pcbRead Where to store the amount of data written, optional.
125 * @param pvUser Opaque user data passed in RTFuzzCtxCreateFromState().
126 */
127typedef DECLCALLBACK(int) FNRTFUZZCTXIMPORT(RTFUZZCTX hFuzzCtx, void *pvBuf, size_t cbRead, size_t *pcbRead, void *pvUser);
128/** Pointer to a fuzzing context state export callback. */
129typedef FNRTFUZZCTXIMPORT *PFNRTFUZZCTXIMPORT;
130
131
132/**
133 * Creates a new fuzzing context.
134 *
135 * @returns IPRT status code.
136 * @param phFuzzCtx Where to store the handle to the fuzzing context on success.
137 * @param enmType Fuzzing context data type.
138 */
139RTDECL(int) RTFuzzCtxCreate(PRTFUZZCTX phFuzzCtx, RTFUZZCTXTYPE enmType);
140
141/**
142 * Creates a new fuzzing context from the given state.
143 *
144 * @returns IPRT status code.
145 * @param phFuzzCtx Where to store the handle to the fuzzing context on success.
146 * @param pfnImport State import callback.
147 * @param pvUser Opaque user data to pass to the callback.
148 */
149RTDECL(int) RTFuzzCtxCreateFromState(PRTFUZZCTX phFuzzCtx, PFNRTFUZZCTXIMPORT pfnImport, void *pvUser);
150
151/**
152 * Creates a new fuzzing context loading the state from the given memory buffer.
153 *
154 * @returns IPRT status code.
155 * @param phFuzzCtx Where to store the handle to the fuzzing context on success.
156 * @param pvState Pointer to the memory containing the state.
157 * @param cbState Size of the state buffer.
158 */
159RTDECL(int) RTFuzzCtxCreateFromStateMem(PRTFUZZCTX phFuzzCtx, const void *pvState, size_t cbState);
160
161/**
162 * Creates a new fuzzing context loading the state from the given file.
163 *
164 * @returns IPRT status code.
165 * @param phFuzzCtx Where to store the handle to the fuzzing context on success.
166 * @param pszFilename File to load the fuzzing context from.
167 */
168RTDECL(int) RTFuzzCtxCreateFromStateFile(PRTFUZZCTX phFuzzCtx, const char *pszFilename);
169
170/**
171 * Retains a reference to the given fuzzing context.
172 *
173 * @returns New reference count on success.
174 * @param hFuzzCtx Handle of the fuzzing context.
175 */
176RTDECL(uint32_t) RTFuzzCtxRetain(RTFUZZCTX hFuzzCtx);
177
178/**
179 * Releases a reference from the given fuzzing context, destroying it when reaching 0.
180 *
181 * @returns New reference count on success, 0 if the fuzzing context got destroyed.
182 * @param hFuzzCtx Handle of the fuzzing context.
183 */
184RTDECL(uint32_t) RTFuzzCtxRelease(RTFUZZCTX hFuzzCtx);
185
186/**
187 * Exports the given fuzzing context state.
188 *
189 * @returns IPRT statuse code
190 * @param hFuzzCtx The fuzzing context to export.
191 * @param pfnExport Export callback.
192 * @param pvUser Opaque user data to pass to the callback.
193 */
194RTDECL(int) RTFuzzCtxStateExport(RTFUZZCTX hFuzzCtx, PFNRTFUZZCTXEXPORT pfnExport, void *pvUser);
195
196/**
197 * Exports the given fuzzing context state to memory allocating the buffer.
198 *
199 * @returns IPRT status code.
200 * @param hFuzzCtx The fuzzing context to export.
201 * @param ppvState Where to store the pointer to the memory containing state on success.
202 * Free with RTMemFree().
203 * @param pcbState Where to store the size of the state in bytes.
204 */
205RTDECL(int) RTFuzzCtxStateExportToMem(RTFUZZCTX hFuzzCtx, void **ppvState, size_t *pcbState);
206
207/**
208 * Exports the given fuzzing context state to the given file.
209 *
210 * @returns IPRT status code.
211 * @param hFuzzCtx The fuzzing context to export.
212 * @param pszFilename The file to save the state to.
213 */
214RTDECL(int) RTFuzzCtxStateExportToFile(RTFUZZCTX hFuzzCtx, const char *pszFilename);
215
216/**
217 * Adds a new seed to the input corpus of the given fuzzing context.
218 *
219 * @returns IPRT status code.
220 * @param hFuzzCtx The fuzzing context handle.
221 * @param pvInput The pointer to the input buffer.
222 * @param cbInput Size of the input buffer.
223 */
224RTDECL(int) RTFuzzCtxCorpusInputAdd(RTFUZZCTX hFuzzCtx, const void *pvInput, size_t cbInput);
225
226/**
227 * Adds a new seed to the input corpus of the given fuzzing context from the given file.
228 *
229 * @returns IPRT status code.
230 * @param hFuzzCtx The fuzzing context handle.
231 * @param pszFilename The filename to load the seed from.
232 */
233RTDECL(int) RTFuzzCtxCorpusInputAddFromFile(RTFUZZCTX hFuzzCtx, const char *pszFilename);
234
235/**
236 * Adds a new seed to the input corpus of the given fuzzing context from the given VFS file.
237 *
238 * @returns IPRT status code.
239 * @param hFuzzCtx The fuzzing context handle.
240 * @param hVfsFile The VFS file handle to load the seed from.
241 */
242RTDECL(int) RTFuzzCtxCorpusInputAddFromVfsFile(RTFUZZCTX hFuzzCtx, RTVFSFILE hVfsFile);
243
244/**
245 * Adds new seeds to the input corpus of the given fuzzing context from the given directory.
246 *
247 * Will only process regular files, i.e. ignores directories, symbolic links, devices, fifos
248 * and such.
249 *
250 * @returns IPRT status code.
251 * @param hFuzzCtx The fuzzing context handle.
252 * @param pszDirPath The directory to load seeds from.
253 */
254RTDECL(int) RTFuzzCtxCorpusInputAddFromDirPath(RTFUZZCTX hFuzzCtx, const char *pszDirPath);
255
256/**
257 * Restricts the maximum input size to generate by the fuzzing context.
258 *
259 * @returns IPRT status code
260 * @param hFuzzCtx The fuzzing context handle.
261 * @param cbMax Maximum input size in bytes.
262 */
263RTDECL(int) RTFuzzCtxCfgSetInputSeedMaximum(RTFUZZCTX hFuzzCtx, size_t cbMax);
264
265/**
266 * Returns the maximum input size of the given fuzzing context.
267 *
268 * @returns Maximum input size generated in bytes.
269 * @param hFuzzCtx The fuzzing context handle.
270 */
271RTDECL(size_t) RTFuzzCtxCfgGetInputSeedMaximum(RTFUZZCTX hFuzzCtx);
272
273/**
274 * Sets flags controlling the behavior of the fuzzing context.
275 *
276 * @returns IPRT status code.
277 * @param hFuzzCtx The fuzzing context handle.
278 * @param fFlags Flags controlling the fuzzing context, RTFUZZCTX_F_XXX.
279 */
280RTDECL(int) RTFuzzCtxCfgSetBehavioralFlags(RTFUZZCTX hFuzzCtx, uint32_t fFlags);
281
282/**
283 * Returns the current set behavioral flags for the given fuzzing context.
284 *
285 * @returns Behavioral flags of the given fuzzing context.
286 * @param hFuzzCtx The fuzzing context handle.
287 */
288RTDECL(uint32_t) RTFuzzCfgGetBehavioralFlags(RTFUZZCTX hFuzzCtx);
289
290/**
291 * Sets the temporary directory used by the fuzzing context.
292 *
293 * @returns IPRT status code.
294 * @param hFuzzCtx The fuzzing context handle.
295 * @param pszPathTmp The directory for the temporary state.
296 */
297RTDECL(int) RTFuzzCtxCfgSetTmpDirectory(RTFUZZCTX hFuzzCtx, const char *pszPathTmp);
298
299/**
300 * Returns the current temporary directory.
301 *
302 * @returns Current temporary directory.
303 * @param hFuzzCtx The fuzzing context handle.
304 */
305RTDECL(const char *) RTFuzzCtxCfgGetTmpDirectory(RTFUZZCTX hFuzzCtx);
306
307/**
308 * Reseeds the PRNG of the given fuzzing context.
309 *
310 * @returns IPRT status code.
311 * @param hFuzzCtx The fuzzing context handle.
312 * @param uSeed The new seed.
313 */
314RTDECL(int) RTFuzzCtxReseed(RTFUZZCTX hFuzzCtx, uint64_t uSeed);
315
316/**
317 * Generates a new input from the given fuzzing context and returns it.
318 *
319 * @returns IPRT status code.
320 * @param hFuzzCtx The fuzzing context handle.
321 * @param phFuzzInput Where to store the handle to the fuzzed input on success.
322 */
323RTDECL(int) RTFuzzCtxInputGenerate(RTFUZZCTX hFuzzCtx, PRTFUZZINPUT phFuzzInput);
324
325
326/**
327 * Retains a reference to the given fuzzing input handle.
328 *
329 * @returns New reference count on success.
330 * @param hFuzzInput The fuzzing input handle.
331 */
332RTDECL(uint32_t) RTFuzzInputRetain(RTFUZZINPUT hFuzzInput);
333
334/**
335 * Releases a reference from the given fuzzing input handle, destroying it when reaching 0.
336 *
337 * @returns New reference count on success, 0 if the fuzzing input got destroyed.
338 * @param hFuzzInput The fuzzing input handle.
339 */
340RTDECL(uint32_t) RTFuzzInputRelease(RTFUZZINPUT hFuzzInput);
341
342/**
343 * Queries the data pointer and size of the given fuzzed input blob.
344 *
345 * @returns IPRT status code
346 * @param hFuzzInput The fuzzing input handle.
347 * @param ppv Where to store the pointer to the input data on success.
348 * @param pcb Where to store the size of the input data on success.
349 */
350RTDECL(int) RTFuzzInputQueryBlobData(RTFUZZINPUT hFuzzInput, void **ppv, size_t *pcb);
351
352/**
353 * Processes the given data stream for a streamed fuzzing context.
354 *
355 * @returns IPRT status code.
356 * @param hFuzzInput The fuzzing input handle.
357 * @param pvBuf The data buffer.
358 * @param cbBuf Size of the buffer.
359 */
360RTDECL(int) RTFuzzInputMutateStreamData(RTFUZZINPUT hFuzzInput, void *pvBuf, size_t cbBuf);
361
362/**
363 * Queries the string of the MD5 digest for the given fuzzed input.
364 *
365 * @returns IPRT status code.
366 * @retval VERR_BUFFER_OVERFLOW if the size of the string buffer is not sufficient.
367 * @param hFuzzInput The fuzzing input handle.
368 * @param pszDigest Where to store the digest string and a closing terminator.
369 * @param cchDigest Size of the string buffer in characters (including the zero terminator).
370 */
371RTDECL(int) RTFuzzInputQueryDigestString(RTFUZZINPUT hFuzzInput, char *pszDigest, size_t cchDigest);
372
373/**
374 * Writes the given fuzzing input to the given file.
375 *
376 * @returns IPRT status code.
377 * @param hFuzzInput The fuzzing input handle.
378 * @param pszFilename The filename to store the input to.
379 */
380RTDECL(int) RTFuzzInputWriteToFile(RTFUZZINPUT hFuzzInput, const char *pszFilename);
381
382/**
383 * Adds the given fuzzed input to the input corpus of the owning context.
384 *
385 * @returns IPRT status code.
386 * @retval VERR_ALREADY_EXISTS if the input exists already.
387 * @param hFuzzInput The fuzzing input handle.
388 */
389RTDECL(int) RTFuzzInputAddToCtxCorpus(RTFUZZINPUT hFuzzInput);
390
391/**
392 * Removes the given fuzzed input from the input corpus of the owning context.
393 *
394 * @returns IPRT status code.
395 * @retval VERR_NOT_FOUND if the input is not part of the corpus.
396 * @param hFuzzInput The fuzzing input handle.
397 */
398RTDECL(int) RTFuzzInputRemoveFromCtxCorpus(RTFUZZINPUT hFuzzInput);
399
400
401/**
402 * Creates a new fuzzed target recorder.
403 *
404 * @returns IPRT status code.
405 * @param phFuzzTgtRec Where to store the handle to the fuzzed target recorder on success.
406 */
407RTDECL(int) RTFuzzTgtRecorderCreate(PRTFUZZTGTREC phFuzzTgtRec);
408
409/**
410 * Retains a reference to the given fuzzed target recorder handle.
411 *
412 * @returns New reference count on success.
413 * @param hFuzzTgtRec The fuzzed target recorder handle.
414 */
415RTDECL(uint32_t) RTFuzzTgtRecorderRetain(RTFUZZTGTREC hFuzzTgtRec);
416
417/**
418 * Releases a reference from the given fuzzed target recorder handle, destroying it when reaching 0.
419 *
420 * @returns New reference count on success, 0 if the fuzzed target recorder got destroyed.
421 * @param hFuzzTgtRec The fuzzed target recorder handle.
422 */
423RTDECL(uint32_t) RTFuzzTgtRecorderRelease(RTFUZZTGTREC hFuzzTgtRec);
424
425/**
426 * Creates a new empty fuzzed target state.
427 *
428 * @returns IPRT status code.
429 * @param hFuzzTgtRec The fuzzed target recorder handle.
430 * @param phFuzzTgtState Where to store the handle to the fuzzed target state on success.
431 */
432RTDECL(int) RTFuzzTgtRecorderCreateNewState(RTFUZZTGTREC hFuzzTgtRec, PRTFUZZTGTSTATE phFuzzTgtState);
433
434/**
435 * Retains a reference to the given fuzzed target state handle.
436 *
437 * @returns New reference count on success.
438 * @param hFuzzTgtState The fuzzed target state handle.
439 */
440RTDECL(uint32_t) RTFuzzTgtStateRetain(RTFUZZTGTSTATE hFuzzTgtState);
441
442/**
443 * Releases a reference from the given fuzzed target state handle, destroying it when reaching 0.
444 *
445 * @returns New reference count on success, 0 if the fuzzed target recorder got destroyed.
446 * @param hFuzzTgtState The fuzzed target state handle.
447 */
448RTDECL(uint32_t) RTFuzzTgtStateRelease(RTFUZZTGTSTATE hFuzzTgtState);
449
450/**
451 * Resets the given fuzzed target state to an empty state (keeping allocated memory).
452 *
453 * @returns IPRT status code.
454 * @param hFuzzTgtState The fuzzed target state handle.
455 *
456 * @note Useful when the state is not added to the recorded set to avoid allocating memory.
457 */
458RTDECL(int) RTFuzzTgtStateReset(RTFUZZTGTSTATE hFuzzTgtState);
459
460/**
461 * Finalizes the given fuzzed target state, making it readonly.
462 *
463 * @returns IPRT status code.
464 * @param hFuzzTgtState The fuzzed target state handle.
465 */
466RTDECL(int) RTFuzzTgtStateFinalize(RTFUZZTGTSTATE hFuzzTgtState);
467
468/**
469 * Adds the given state to the set for the owning target recorder.
470 *
471 * @returns IPRT status code.
472 * @retval VERR_ALREADY_EXISTS if the state is already existing in the recorder set.
473 * @param hFuzzTgtState The fuzzed target state handle.
474 *
475 * @note This also finalizes the target state if not already done.
476 */
477RTDECL(int) RTFuzzTgtStateAddToRecorder(RTFUZZTGTSTATE hFuzzTgtState);
478
479/**
480 * Appends the given stdout output to the given target state.
481 *
482 * @returns IPRT status code.
483 * @param hFuzzTgtState The fuzzed target state handle.
484 * @param pvStdOut Pointer to the stdout data buffer.
485 * @param cbStdOut Size of the stdout data buffer in bytes.
486 */
487RTDECL(int) RTFuzzTgtStateAppendStdoutFromBuf(RTFUZZTGTSTATE hFuzzTgtState, const void *pvStdOut, size_t cbStdOut);
488
489/**
490 * Appends the given stderr output to the given target state.
491 *
492 * @returns IPRT status code.
493 * @param hFuzzTgtState The fuzzed target state handle.
494 * @param pvStdErr Pointer to the stderr data buffer.
495 * @param cbStdErr Size of the stderr data buffer in bytes.
496 */
497RTDECL(int) RTFuzzTgtStateAppendStderrFromBuf(RTFUZZTGTSTATE hFuzzTgtState, const void *pvStdErr, size_t cbStdErr);
498
499/**
500 * Appends the given stdout output to the given target state, reading from the given pipe.
501 *
502 * @returns IPRT status code.
503 * @param hFuzzTgtState The fuzzed target state handle.
504 * @param hPipe The stdout pipe to read the data from.
505 */
506RTDECL(int) RTFuzzTgtStateAppendStdoutFromPipe(RTFUZZTGTSTATE hFuzzTgtState, RTPIPE hPipe);
507
508/**
509 * Appends the given stderr output to the given target state, reading from the given pipe.
510 *
511 * @returns IPRT status code.
512 * @param hFuzzTgtState The fuzzed target state handle.
513 * @param hPipe The stdout pipe to read the data from.
514 */
515RTDECL(int) RTFuzzTgtStateAppendStderrFromPipe(RTFUZZTGTSTATE hFuzzTgtState, RTPIPE hPipe);
516
517
518/**
519 * Fuzzed binary input channel.
520 */
521typedef enum RTFUZZOBSINPUTCHAN
522{
523 /** Invalid. */
524 RTFUZZOBSINPUTCHAN_INVALID = 0,
525 /** File input. */
526 RTFUZZOBSINPUTCHAN_FILE,
527 /** Input over stdin. */
528 RTFUZZOBSINPUTCHAN_STDIN,
529 /** The binary is a fuzzing aware client using the
530 * specified protocol over stdin/stdout. */
531 RTFUZZOBSINPUTCHAN_FUZZING_AWARE_CLIENT,
532 /** TCP server. */
533 RTFUZZOBSINPUTCHAN_TCP_SERVER,
534 /** TCP client. */
535 RTFUZZOBSINPUTCHAN_TCP_CLIENT,
536 /** UDP server. */
537 RTFUZZOBSINPUTCHAN_UDP_SERVER,
538 /** UDP client. */
539 RTFUZZOBSINPUTCHAN_UDP_CLIENT,
540 /** 32bit hack. */
541 RTFUZZOBSINPUTCHAN_32BIT_HACK = 0x7fffffff
542} RTFUZZOBSINPUTCHAN;
543
544/**
545 * Fuzzing observer statistics.
546 */
547typedef struct RTFUZZOBSSTATS
548{
549 /** Number of fuzzed inputs per second. */
550 uint32_t cFuzzedInputsPerSec;
551 /** Number of overall fuzzed inputs. */
552 uint32_t cFuzzedInputs;
553 /** Number of observed hangs. */
554 uint32_t cFuzzedInputsHang;
555 /** Number of observed crashes. */
556 uint32_t cFuzzedInputsCrash;
557} RTFUZZOBSSTATS;
558/** Pointer to a fuzzing observer statistics record. */
559typedef RTFUZZOBSSTATS *PRTFUZZOBSSTATS;
560
561/**
562 * Creates a new fuzzing observer.
563 *
564 * @returns IPRT status code.
565 * @param phFuzzObs Where to store the fuzzing observer handle on success.
566 * @param enmType Fuzzing context data type.
567 */
568RTDECL(int) RTFuzzObsCreate(PRTFUZZOBS phFuzzObs, RTFUZZCTXTYPE enmType);
569
570/**
571 * Destroys a previously created fuzzing observer.
572 *
573 * @returns IPRT status code.
574 * @param hFuzzObs The fuzzing observer handle.
575 */
576RTDECL(int) RTFuzzObsDestroy(RTFUZZOBS hFuzzObs);
577
578/**
579 * Queries the internal fuzzing context of the given observer.
580 *
581 * @returns IPRT status code.
582 * @param hFuzzObs The fuzzing observer handle.
583 * @param phFuzzCtx Where to store the handle to the fuzzing context on success.
584 *
585 * @note The fuzzing context handle should be released with RTFuzzCtxRelease() when not used anymore.
586 */
587RTDECL(int) RTFuzzObsQueryCtx(RTFUZZOBS hFuzzObs, PRTFUZZCTX phFuzzCtx);
588
589/**
590 * Queries the current statistics for the given fuzzing observer.
591 *
592 * @returns IPRT status code.
593 * @param hFuzzObs The fuzzing observer handle.
594 * @param pStats Where to store the statistics to.
595 */
596RTDECL(int) RTFuzzObsQueryStats(RTFUZZOBS hFuzzObs, PRTFUZZOBSSTATS pStats);
597
598/**
599 * Sets the temp directory for the given fuzzing observer.
600 *
601 * @returns IPRT status code.
602 * @param hFuzzObs The fuzzing observer handle.
603 * @param pszTmp The temp directory path.
604 */
605RTDECL(int) RTFuzzObsSetTmpDirectory(RTFUZZOBS hFuzzObs, const char *pszTmp);
606
607/**
608 * Sets the directory to store results to.
609 *
610 * @returns IPRT status code.
611 * @param hFuzzObs The fuzzing observer handle.
612 * @param pszResults The path to store the results.
613 */
614RTDECL(int) RTFuzzObsSetResultDirectory(RTFUZZOBS hFuzzObs, const char *pszResults);
615
616/**
617 * Sets the binary to run for each fuzzed input.
618 *
619 * @returns IPRT status code.
620 * @param hFuzzObs The fuzzing observer handle.
621 * @param pszBinary The binary path.
622 * @param enmInputChan The input channel to use.
623 */
624RTDECL(int) RTFuzzObsSetTestBinary(RTFUZZOBS hFuzzObs, const char *pszBinary, RTFUZZOBSINPUTCHAN enmInputChan);
625
626/**
627 * Sets additional arguments to run the binary with.
628 *
629 * @returns IPRT status code.
630 * @param hFuzzObs The fuzzing observer handle.
631 * @param papszArgs Pointer to the array of arguments.
632 * @param cArgs Number of arguments.
633 */
634RTDECL(int) RTFuzzObsSetTestBinaryArgs(RTFUZZOBS hFuzzObs, const char * const *papszArgs, unsigned cArgs);
635
636/**
637 * Starts fuzzing the set binary.
638 *
639 * @returns IPRT status code.
640 * @param hFuzzObs The fuzzing observer handle.
641 * @param cProcs Number of processes to run simulteanously,
642 * 0 will create as many processes as there are CPUs available.
643 */
644RTDECL(int) RTFuzzObsExecStart(RTFUZZOBS hFuzzObs, uint32_t cProcs);
645
646/**
647 * Stops the fuzzing process.
648 *
649 * @returns IPRT status code.
650 * @param hFuzzObs The fuzzing observer handle.
651 */
652RTDECL(int) RTFuzzObsExecStop(RTFUZZOBS hFuzzObs);
653
654
655/**
656 * A fuzzing master program.
657 *
658 * @returns Program exit code.
659 *
660 * @param cArgs The number of arguments.
661 * @param papszArgs The argument vector. (Note that this may be
662 * reordered, so the memory must be writable.)
663 */
664RTR3DECL(RTEXITCODE) RTFuzzCmdMaster(unsigned cArgs, char **papszArgs);
665
666
667/**
668 * Client input consumption callback.
669 *
670 * @returns IPRT status code.
671 * @retval VINF_SUCCESS the fuzzed code accepted the input.
672 * @retval VERR_* the client rejected the input while parsing it.
673 * @param pvBuf The buffer containing the input data.
674 * @param cbBuf Size of the buffer in bytes.
675 * @param pvUser Opaque user data.
676 */
677typedef DECLCALLBACK(int) FNFUZZCLIENTCONSUME(const void *pvBuf, size_t cbBuf, void *pvUser);
678/** Pointer to a client consumption callback. */
679typedef FNFUZZCLIENTCONSUME *PFNFUZZCLIENTCONSUME;
680
681/**
682 * A fuzzing client program for more efficient fuzzing.
683 *
684 * @returns Program exit code.
685 *
686 * @param cArgs The number of arguments.
687 * @param papszArgs The argument vector. (Note that this may be
688 * reordered, so the memory must be writable.)
689 * @param pfnConsume Input data consumption callback.
690 * @param pvUser Opaque user data to pass to the callback.
691 */
692RTR3DECL(RTEXITCODE) RTFuzzCmdFuzzingClient(unsigned cArgs, char **papszArgs, PFNFUZZCLIENTCONSUME pfnConsume, void *pvUser);
693/** @} */
694
695RT_C_DECLS_END
696
697#endif /* !IPRT_INCLUDED_fuzz_h */
698
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette