-C Enhance\sfuzzershell.c\sto\sread\sand\sexecute\sSQL\scommands\sin\sthe\sautoexec\stable\nof\sthe\sdatabase\sunder\stest.\s\sAdd\sthe\sdbfuzz.c\stest\sprogram\scombining\sselected\nfeatures\sof\sfuzzershell.c\sand\sfuzzcheck.c.
-D 2016-12-17T20:27:22.394
+C Refinements\sto\sthe\snew\sdbfuzz\stest\sprogram.
+D 2016-12-17T21:07:30.972
F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
F test/cursorhint.test 7bc346788390475e77a345da2b92270d04d35856
F test/cursorhint2.test fa41f0d997e67db921d08c31e73111b32811201a
F test/date.test a6a5a48b90907bca9fbcc79a30be5a715c1ab2fc
-F test/dbfuzz.c 2bf7858028c0c437ccffc5795f791c495800cd9b
+F test/dbfuzz.c 8cc2bdb818b4483a052f9f80f96be74cbd9a6e1d
F test/dbstatus.test 73149851b3aff14fc6db478e58f9083a66422cf5
F test/dbstatus2.test e93ab03bfae6d62d4d935f20de928c19ca0ed0ab
F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8dedd6ad44bd1d103dced9d1350188cb2327128d
-R 467cdb2635ae3db86cb6ad0c3fe29c15
+P ef6e071a62cd79a0edbbef9f41ca9482540e5cb8
+R dc4a1399a03b50b6a494c9549eb51d65
U drh
-Z 6af4ccd37cf6da1faf8a726dcd8a746b
+Z 264edff2f6705a86fbfac5952dd5c460
** are run against the database to ensure that SQLite can safely handle
** the fuzzed database.
*/
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return (int)(isNeg? -v : v);
}
-/*
-** This callback is invoked by sqlite3_exec() to return query results.
-*/
-static int execCallback(void *NotUsed, int argc, char **argv, char **colv){
- int i;
- static unsigned cnt = 0;
- printf("ROW #%u:\n", ++cnt);
- if( argv ){
- for(i=0; i<argc; i++){
- printf(" %s=", colv[i]);
- if( argv[i] ){
- printf("[%s]\n", argv[i]);
- }else{
- printf("NULL\n");
- }
- }
- }
- fflush(stdout);
- return 0;
-}
-static int execNoop(void *NotUsed, int argc, char **argv, char **colv){
- return 0;
-}
-
/*
** This callback is invoked by sqlite3_log().
*/
}
#endif
+/*
+** Allowed values for the runFlags parameter to runSql()
+*/
+#define SQL_TRACE 0x0001 /* Print each SQL statement as it is prepared */
+#define SQL_OUTPUT 0x0002 /* Show the SQL output */
+/*
+** Run multiple commands of SQL. Similar to sqlite3_exec(), but does not
+** stop if an error is encountered.
+*/
+static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){
+ const char *zMore;
+ const char *zEnd = &zSql[strlen(zSql)];
+ sqlite3_stmt *pStmt;
+
+ while( zSql && zSql[0] ){
+ zMore = 0;
+ pStmt = 0;
+ sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zMore);
+ assert( zMore<=zEnd );
+ if( zMore==zSql ) break;
+ if( runFlags & SQL_TRACE ){
+ const char *z = zSql;
+ int n;
+ while( z<zMore && ISSPACE(z[0]) ) z++;
+ n = (int)(zMore - z);
+ while( n>0 && ISSPACE(z[n-1]) ) n--;
+ if( n==0 ) break;
+ if( pStmt==0 ){
+ printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db));
+ }else{
+ printf("TRACE: %.*s\n", n, z);
+ }
+ }
+ zSql = zMore;
+ if( pStmt ){
+ if( (runFlags & SQL_OUTPUT)==0 ){
+ while( SQLITE_ROW==sqlite3_step(pStmt) ){}
+ }else{
+ int nCol = -1;
+ int nRow;
+ for(nRow=0; SQLITE_ROW==sqlite3_step(pStmt); nRow++){
+ int i;
+ if( nCol<0 ){
+ nCol = sqlite3_column_count(pStmt);
+ }
+ for(i=0; i<nCol; i++){
+ int eType = sqlite3_column_type(pStmt,i);
+ printf("ROW[%d].%s = ", nRow, sqlite3_column_name(pStmt,i));
+ switch( eType ){
+ case SQLITE_NULL: {
+ printf("NULL\n");
+ break;
+ }
+ case SQLITE_INTEGER: {
+ printf("INT %s\n", sqlite3_column_text(pStmt,i));
+ break;
+ }
+ case SQLITE_FLOAT: {
+ printf("FLOAT %s\n", sqlite3_column_text(pStmt,i));
+ break;
+ }
+ case SQLITE_TEXT: {
+ printf("TEXT [%s]\n", sqlite3_column_text(pStmt,i));
+ break;
+ }
+ case SQLITE_BLOB: {
+ printf("BLOB (%d bytes)\n", sqlite3_column_bytes(pStmt,i));
+ break;
+ }
+ }
+ }
+ }
+ }
+ sqlite3_finalize(pStmt);
+ }
+ }
+}
int main(int argc, char **argv){
int i; /* Loop counter */
- int nDb; /* Number of databases to fuzz */
+ int nDb = 0; /* Number of databases to fuzz */
const char **azDb = 0; /* Names of the databases (limit: 20) */
int verboseFlag = 0; /* True for extra output */
- int traceFlag = 0; /* True to trace results */
int noLookaside = 0; /* Disable lookaside if true */
int vdbeLimitFlag = 0; /* Stop after 100,000 VDBE ops */
int nHeap = 0; /* True for fixed heap size */
sqlite3 *db; /* The database connection */
sqlite3_stmt *pStmt; /* A single SQL statement */
Str sql; /* SQL to run */
+ unsigned runFlags = 0; /* Flags passed to runSql */
for(i=1; i<argc; i++){
const char *z = argv[i];
if( i==argc-1 ) fatalError("missing argument to %s", argv[i]);
iTimeout = integerValue(argv[++i]);
}else if( strcmp(z, "trace")==0 ){
- traceFlag = 1;
+ runFlags |= SQL_OUTPUT|SQL_TRACE;
}else if( strcmp(z, "limit-vdbe")==0 ){
vdbeLimitFlag = 1;
}else if( strcmp(z, "v")==0 || strcmp(z, "verbose")==0 ){
verboseFlag = 1;
+ runFlags |= SQL_TRACE;
}else{
fatalError("unknown command-line option: \"%s\"\n", argv[i]);
}
signal(SIGALRM, timeoutHandler);
#endif
for(i=0; i<nDb; i++){
- StrFree(&sql);
-
if( verboseFlag && nDb>1 ){
printf("DATABASE-FILE: %s\n", azDb[i]);
fflush(stdout);
}
sqlite3_finalize(pStmt);
StrAppend(&sql, "PRAGMA integrity_check;\n");
- if( traceFlag ){
- char *zErrMsg = 0;
- rc = sqlite3_exec(db, StrStr(&sql), execCallback, 0, &zErrMsg);
- if( zErrMsg ){
- printf("ERRMSG: %s\n", zErrMsg);
- sqlite3_free(zErrMsg);
- }
- }else {
- rc = sqlite3_exec(db, StrStr(&sql), execNoop, 0, 0);
- }
+ runSql(db, StrStr(&sql), runFlags);
sqlite3_close(db);
reformatVfs();
StrFree(&sql);