1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Enhance fuzzcheck.c to accept database-specific configuration parameters in

the option CONFIG table.  Add the fuzzdata5.db fuzz database containing
test cases from OSS-FUZZ.

FossilOrigin-Name: a71fad4538311ede111815d221d9eb8d9018092b
This commit is contained in:
drh
2016-11-14 18:27:41 +00:00
parent 55377b4717
commit 362b66f051
7 changed files with 67 additions and 23 deletions

View File

@ -838,10 +838,12 @@ int main(int argc, char **argv){
int sqlFuzz = 0; /* True for SQL fuzz testing. False for DB fuzz */
int iTimeout = 120; /* Default 120-second timeout */
int nMem = 0; /* Memory limit */
int nMemThisDb = 0; /* Memory limit set by the CONFIG table */
char *zExpDb = 0; /* Write Databases to files in this directory */
char *zExpSql = 0; /* Write SQL to files in this directory */
void *pHeap = 0; /* Heap for use by SQLite */
int ossFuzz = 0; /* enable OSS-FUZZ testing */
int ossFuzzThisDb = 0; /* ossFuzz value for this particular database */
iBegin = timeOfDay();
#ifdef __unix__
@ -981,6 +983,34 @@ int main(int argc, char **argv){
sqlite3_free(zSql);
if( rc ) fatalError("cannot change description: %s", sqlite3_errmsg(db));
}
ossFuzzThisDb = ossFuzz;
/* If the CONFIG(name,value) table exists, read db-specific settings
** from that table */
if( sqlite3_table_column_metadata(db,0,"config",0,0,0,0,0,0)==SQLITE_OK ){
rc = sqlite3_prepare_v2(db, "SELECT name, value FROM config", -1, &pStmt, 0);
if( rc ) fatalError("cannot prepare query of CONFIG table: %s",
sqlite3_errmsg(db));
while( SQLITE_ROW==sqlite3_step(pStmt) ){
const char *zName = (const char *)sqlite3_column_text(pStmt,0);
if( zName==0 ) continue;
if( strcmp(zName, "oss-fuzz")==0 ){
ossFuzzThisDb = sqlite3_column_int(pStmt,1);
if( verboseFlag ) printf("Config: oss-fuzz=%d\n", ossFuzzThisDb);
}
if( strcmp(zName, "limit-mem")==0 ){
#if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5)
fatalError("the limit-mem option requires -DSQLITE_ENABLE_MEMSYS5"
" or _MEMSYS3");
#else
nMemThisDb = sqlite3_column_int(pStmt,1);
if( verboseFlag ) printf("Config: limit-mem=%d\n", nMemThisDb);
#endif
}
}
sqlite3_finalize(pStmt);
}
if( zInsSql ){
sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
readfileFunc, 0, 0);
@ -1096,13 +1126,13 @@ int main(int argc, char **argv){
}
/* Limit available memory, if requested */
if( nMem>0 ){
if( nMemThisDb>0 ){
sqlite3_shutdown();
pHeap = malloc(nMem);
pHeap = realloc(pHeap, nMemThisDb);
if( pHeap==0 ){
fatalError("failed to allocate %d bytes of heap memory", nMem);
}
sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMem, 128);
sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMemThisDb, 128);
}
/* Register the in-memory virtual filesystem
@ -1133,7 +1163,7 @@ int main(int argc, char **argv){
}
}
createVFile("main.db", pDb->sz, pDb->a);
if( ossFuzz ){
if( ossFuzzThisDb ){
#ifndef SQLITE_OSS_FUZZ
fatalError("--oss-fuzz not supported: recompile with -DSQLITE_OSS_FUZZ");
#else