aboutsummaryrefslogtreecommitdiff
path: root/test/ossshell.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2016-11-14 17:25:57 +0000
committerdrh <drh@noemail.net>2016-11-14 17:25:57 +0000
commit55377b47174f456fc6bb93e1096435a0071d4ea1 (patch)
treed80399b0c9c81f3e657469c91e3b9f3c1563817f /test/ossshell.c
parent2adb878b1fb7d02c4c247889dbd98c8bfbb96c49 (diff)
downloadsqlite-55377b47174f456fc6bb93e1096435a0071d4ea1.tar.gz
sqlite-55377b47174f456fc6bb93e1096435a0071d4ea1.zip
Fix the ossfuzz.c test module so that it does not segfault after a
"PRAGMA empty_result_callbacks=1;". Add the ossshell.c program for simple command-line testing of ossfuzz.c. FossilOrigin-Name: 6f2d43eca68175ed28abae3afa792095af906af2
Diffstat (limited to 'test/ossshell.c')
-rw-r--r--test/ossshell.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/ossshell.c b/test/ossshell.c
new file mode 100644
index 000000000..15902a912
--- /dev/null
+++ b/test/ossshell.c
@@ -0,0 +1,61 @@
+/*
+** This is a test interface for the ossfuzz.c module. The ossfuzz.c module
+** is an adaptor for OSS-FUZZ. (https://github.com/google/oss-fuzz)
+**
+** This program links against ossfuzz.c. It reads files named on the
+** command line and passes them one by one into ossfuzz.c.
+*/
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "sqlite3.h"
+
+/*
+** The entry point in ossfuzz.c that this routine will be calling
+*/
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
+
+
+/*
+** Read files named on the command-line and invoke the fuzzer for
+** each one.
+*/
+int main(int argc, char **argv){
+ FILE *in;
+ int i;
+ int nErr = 0;
+ uint8_t *zBuf = 0;
+ size_t sz;
+
+ for(i=1; i<argc; i++){
+ const char *zFilename = argv[i];
+ in = fopen(zFilename, "rb");
+ if( in==0 ){
+ fprintf(stderr, "cannot open \"%s\"\n", zFilename);
+ nErr++;
+ continue;
+ }
+ fseek(in, 0, SEEK_END);
+ sz = ftell(in);
+ rewind(in);
+ zBuf = realloc(zBuf, sz);
+ if( zBuf==0 ){
+ fprintf(stderr, "cannot malloc() for %d bytes\n", (int)sz);
+ exit(1);
+ }
+ if( fread(zBuf, sz, 1, in)!=1 ){
+ fprintf(stderr, "cannot read %d bytes from \"%s\"\n",
+ (int)sz, zFilename);
+ nErr++;
+ }else{
+ printf("%s... ", zFilename);
+ fflush(stdout);
+ (void)LLVMFuzzerTestOneInput(zBuf, sz);
+ printf("ok\n");
+ }
+ fclose(in);
+ }
+ free(zBuf);
+ return nErr;
+}