2 ** This is a test interface for the ossfuzz.c module. The ossfuzz.c module
3 ** is an adaptor for OSS-FUZZ. (https://github.com/google/oss-fuzz)
5 ** This program links against ossfuzz.c. It reads files named on the
6 ** command line and passes them one by one into ossfuzz.c.
16 ** The entry point in ossfuzz.c that this routine will be calling
18 int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
);
20 /* Must match equivalent #defines in ossfuzz.c */
21 #define FUZZ_SQL_TRACE 0x0001 /* Set an sqlite3_trace() callback */
22 #define FUZZ_SHOW_MAX_DELAY 0x0002 /* Show maximum progress callback delay */
23 #define FUZZ_SHOW_ERRORS 0x0004 /* Show SQL errors */
24 extern void ossfuzz_set_debug_flags(unsigned);
29 ** Read files named on the command-line and invoke the fuzzer for
32 int main(int argc
, char **argv
){
40 for(i
=1; i
<argc
; i
++){
41 const char *zFilename
= argv
[i
];
42 if( zFilename
[0]=='-' ){
43 if( zFilename
[1]=='-' ) zFilename
++;
44 if( strcmp(zFilename
, "-show-errors")==0 ){
45 mDebug
|= FUZZ_SHOW_ERRORS
;
46 ossfuzz_set_debug_flags(mDebug
);
48 if( strcmp(zFilename
, "-show-max-delay")==0 ){
49 mDebug
|= FUZZ_SHOW_MAX_DELAY
;
50 ossfuzz_set_debug_flags(mDebug
);
52 if( strcmp(zFilename
, "-sql-trace")==0 ){
53 mDebug
|= FUZZ_SQL_TRACE
;
54 ossfuzz_set_debug_flags(mDebug
);
57 printf("unknown option \"%s\"\n", argv
[i
]);
58 printf("should be one of: --show-errors --show-max-delay"
64 in
= fopen(zFilename
, "rb");
66 fprintf(stderr
, "cannot open \"%s\"\n", zFilename
);
70 fseek(in
, 0, SEEK_END
);
73 zBuf
= realloc(zBuf
, sz
);
75 fprintf(stderr
, "cannot malloc() for %d bytes\n", (int)sz
);
78 if( fread(zBuf
, sz
, 1, in
)!=1 ){
79 fprintf(stderr
, "cannot read %d bytes from \"%s\"\n",
83 printf("%s... ", zFilename
);
84 if( mDebug
) printf("\n");
86 (void)LLVMFuzzerTestOneInput(zBuf
, sz
);
87 if( mDebug
) printf("%s: ", zFilename
);