/ Check-in [ea119641]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Separate makefile targets for "dbfuzz2", "dbfuzz2-asan", and "dbfuzz2-msan".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ea119641a7edcd0e1ec14371d93e35f860971888bd98cb0019253358a2ef123b
User & Date: drh 2019-01-11 13:03:06
Context
2019-01-11
13:32
The keywords TRUE and FALSE should only act as boolean literal values if unquoted. check-in: 5547f39d user: drh tags: trunk
13:03
Separate makefile targets for "dbfuzz2", "dbfuzz2-asan", and "dbfuzz2-msan". check-in: ea119641 user: drh tags: trunk
2019-01-10
19:26
Fix a memory leak in fts5 that could occur if scalar function fts5_decode() was passed a corrupt record. check-in: 240f1c0c user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   678    678     -DSQLITE_THREADSAFE=0 \
   679    679     -DSQLITE_OMIT_LOAD_EXTENSION \
   680    680     -DSQLITE_ENABLE_DESERIALIZE \
   681    681     -DSQLITE_DEBUG \
   682    682     -DSQLITE_ENABLE_DBSTAT_VTAB \
   683    683     -DSQLITE_ENABLE_RTREE \
   684    684     -DSQLITE_ENABLE_FTS4 \
   685         -  -DSQLITE_EANBLE_FTS5
          685  +  -DSQLITE_ENABLE_FTS5
   686    686   
   687         -dbfuzz2:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          687  +dbfuzz2$(TEXE):	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          688  +	$(CC) $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          689  +		-DSTANDALONE -o dbfuzz2 \
          690  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
          691  +	mkdir -p dbfuzz2-dir
          692  +	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
          693  +
          694  +dbfuzz2-asan:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          695  +	clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          696  +		-fsanitize=fuzzer,undefined,address -o dbfuzz2-asan \
          697  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
          698  +	mkdir -p dbfuzz2-dir
          699  +	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
          700  +
          701  +dbfuzz2-msan:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
   688    702   	clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
   689         -		-fsanitize=fuzzer,undefined,address -o dbfuzz2 \
   690         -		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c
          703  +		-fsanitize=fuzzer,undefined,memory -o dbfuzz2-msan \
          704  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
   691    705   	mkdir -p dbfuzz2-dir
   692    706   	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
   693    707   
   694    708   mptester$(TEXE):	sqlite3.lo $(TOP)/mptest/mptest.c
   695    709   	$(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.lo \
   696    710   		$(TLIBS) -rpath "$(libdir)"
   697    711   

Changes to test/dbfuzz2.c.

   133    133       newArgv[j++] = argv[i];
   134    134     }
   135    135     newArgv[j] = 0;
   136    136     *pArgv = newArgv;
   137    137     *pArgc = j;
   138    138     return 0;
   139    139   }
          140  +
          141  +#ifdef STANDALONE
          142  +/*
          143  +** Read an entire file into memory.  Space to hold the file comes
          144  +** from malloc().
          145  +*/
          146  +static unsigned char *readFile(const char *zName, int *pnByte){
          147  +  FILE *in = fopen(zName, "rb");
          148  +  long nIn;
          149  +  size_t nRead;
          150  +  unsigned char *pBuf;
          151  +  if( in==0 ) return 0;
          152  +  fseek(in, 0, SEEK_END);
          153  +  nIn = ftell(in);
          154  +  rewind(in);
          155  +  pBuf = malloc( nIn+1 );
          156  +  if( pBuf==0 ){ fclose(in); return 0; }
          157  +  nRead = fread(pBuf, nIn, 1, in);
          158  +  fclose(in);
          159  +  if( nRead!=1 ){
          160  +    free(pBuf);
          161  +    return 0;
          162  +  }
          163  +  pBuf[nIn] = 0;
          164  +  if( pnByte ) *pnByte = nIn;
          165  +  return pBuf;
          166  +}
          167  +#endif /* STANDALONE */
          168  +
          169  +#ifdef STANDALONE
          170  +int main(int argc, char **argv){
          171  +  int i;
          172  +  int prevAmt = -1;
          173  +  LLVMFuzzerInitialize(&argc, &argv);
          174  +  for(i=1; i<argc; i++){
          175  +    unsigned char *pIn;
          176  +    int nIn;
          177  +    pIn = readFile(argv[i], &nIn);
          178  +    if( pIn ){
          179  +      LLVMFuzzerTestOneInput((const uint8_t*)pIn, (size_t)nIn);
          180  +      free(pIn);
          181  +    }
          182  +  }
          183  +  return 0;
          184  +}
          185  +#endif /*STANDALONE*/