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.
18 typedef unsigned char uint8_t;
22 ** The entry point in ossfuzz.c that this routine will be calling
24 int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
);
26 /* Must match equivalent #defines in ossfuzz.c */
27 #define FUZZ_SQL_TRACE 0x0001 /* Set an sqlite3_trace() callback */
28 #define FUZZ_SHOW_MAX_DELAY 0x0002 /* Show maximum progress callback delay */
29 #define FUZZ_SHOW_ERRORS 0x0004 /* Show SQL errors */
30 extern void ossfuzz_set_debug_flags(unsigned);
35 ** Read files named on the command-line and invoke the fuzzer for
38 int main(int argc
, char **argv
){
46 for(i
=1; i
<argc
; i
++){
47 const char *zFilename
= argv
[i
];
48 if( zFilename
[0]=='-' ){
49 if( zFilename
[1]=='-' ) zFilename
++;
50 if( strcmp(zFilename
, "-show-errors")==0 ){
51 mDebug
|= FUZZ_SHOW_ERRORS
;
52 ossfuzz_set_debug_flags(mDebug
);
54 if( strcmp(zFilename
, "-show-max-delay")==0 ){
55 mDebug
|= FUZZ_SHOW_MAX_DELAY
;
56 ossfuzz_set_debug_flags(mDebug
);
58 if( strcmp(zFilename
, "-sql-trace")==0 ){
59 mDebug
|= FUZZ_SQL_TRACE
;
60 ossfuzz_set_debug_flags(mDebug
);
63 printf("unknown option \"%s\"\n", argv
[i
]);
64 printf("should be one of: --show-errors --show-max-delay"
70 in
= fopen(zFilename
, "rb");
72 fprintf(stderr
, "cannot open \"%s\"\n", zFilename
);
76 fseek(in
, 0, SEEK_END
);
79 zBuf
= realloc(zBuf
, sz
);
81 fprintf(stderr
, "cannot malloc() for %d bytes\n", (int)sz
);
84 if( fread(zBuf
, sz
, 1, in
)!=1 ){
85 fprintf(stderr
, "cannot read %d bytes from \"%s\"\n",
89 printf("%s... ", zFilename
);
90 if( mDebug
) printf("\n");
92 (void)LLVMFuzzerTestOneInput(zBuf
, sz
);
93 if( mDebug
) printf("%s: ", zFilename
);