mirror of https://github.com/sqlite/sqlite
Add the --show-errors and --show-max-delay command-line options to the
ossshell test program. FossilOrigin-Name: 626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf
This commit is contained in:
parent
59d705ab80
commit
f53524b4f7
14
manifest
14
manifest
|
@ -1,5 +1,5 @@
|
|||
C Fix\sthe\sMakefile.in\sso\sthat\sit\sbuilds\sthe\sossshell\stest\sprogram\scorrectly.
|
||||
D 2017-03-17T14:15:06.628
|
||||
C Add\sthe\s--show-errors\sand\s--show-max-delay\scommand-line\soptions\sto\sthe\nossshell\stest\sprogram.
|
||||
D 2017-03-17T14:59:40.532
|
||||
F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a
|
||||
|
@ -1009,8 +1009,8 @@ F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da
|
|||
F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd
|
||||
F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3
|
||||
F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f
|
||||
F test/ossfuzz.c 6dc75478809cfbd4609409a87179ddc2ffaa092e8adb27c1982c5a944a7dd81f
|
||||
F test/ossshell.c d9f1a6f43e7bab45d6be857a5800f5d4a1861db3
|
||||
F test/ossfuzz.c 756ca4bede67ec22e3a700b1168bad767dc6fc69ede414c4ab87cfcfcceb4075
|
||||
F test/ossshell.c 296ab63067841bd1b1e97b46a0b2af48ee7f69d50d1a723008bee12dd7122622
|
||||
F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f
|
||||
F test/pager1.test 841868017e9dd3cb459b8d78862091a7d9cff21d
|
||||
F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71
|
||||
|
@ -1566,7 +1566,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P f336fba7d7d41b91a5000d01dddf785821fa79ea31dbd8d1f769d55f7e871896
|
||||
R a0acb13b6691b2f29cdfa3d14a75a6b3
|
||||
P 36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900
|
||||
R 78dfbe98cc4f1c1387677674bd1f6a34
|
||||
U drh
|
||||
Z a464f97090f56a22de007bae0707b7f9
|
||||
Z 8d96b967fb72fb140eaa51fb70892dfa
|
||||
|
|
|
@ -1 +1 @@
|
|||
36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900
|
||||
626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf
|
|
@ -4,8 +4,26 @@
|
|||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "sqlite3.h"
|
||||
|
||||
/* Global debugging settings. OSS-Fuzz will have all debugging turned
|
||||
** off. But if LLVMFuzzerTestOneInput() is called interactively from
|
||||
** the ossshell utility program, then these flags might be set.
|
||||
*/
|
||||
static unsigned mDebug = 0;
|
||||
#define FUZZ_SQL_TRACE 0x0001 /* Set an sqlite3_trace() callback */
|
||||
#define FUZZ_SHOW_MAX_DELAY 0x0002 /* Show maximum progress callback delay */
|
||||
#define FUZZ_SHOW_ERRORS 0x0004 /* Print error messages from SQLite */
|
||||
|
||||
/* The ossshell utility program invokes this interface to see the
|
||||
** debugging flags. Unused by OSS-Fuzz.
|
||||
*/
|
||||
void ossfuzz_set_debug_flags(unsigned x){
|
||||
mDebug = x;
|
||||
}
|
||||
|
||||
/* Return the current real-world time in milliseconds since the
|
||||
** Julian epoch (-4714-11-24).
|
||||
*/
|
||||
|
@ -23,6 +41,17 @@ static sqlite3_int64 timeOfDay(void){
|
|||
return t;
|
||||
}
|
||||
|
||||
/* An instance of the following object is passed by pointer as the
|
||||
** client data to various callbacks.
|
||||
*/
|
||||
typedef struct FuzzCtx {
|
||||
sqlite3 *db; /* The database connection */
|
||||
sqlite3_int64 iCutoffTime; /* Stop processing at this time. */
|
||||
sqlite3_int64 iLastCb; /* Time recorded for previous progress callback */
|
||||
sqlite3_int64 mxInterval; /* Longest interval between two progress calls */
|
||||
unsigned nCb; /* Number of progress callbacks */
|
||||
} FuzzCtx;
|
||||
|
||||
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
|
||||
/*
|
||||
** Progress handler callback.
|
||||
|
@ -30,9 +59,14 @@ static sqlite3_int64 timeOfDay(void){
|
|||
** The argument is the cutoff-time after which all processing should
|
||||
** stop. So return non-zero if the cut-off time is exceeded.
|
||||
*/
|
||||
static int progress_handler(void *pReturn) {
|
||||
sqlite3_int64 iCutoffTime = *(sqlite3_int64*)pReturn;
|
||||
return timeOfDay()>=iCutoffTime;
|
||||
static int progress_handler(void *pClientData) {
|
||||
FuzzCtx *p = (FuzzCtx*)pClientData;
|
||||
sqlite3_int64 iNow = timeOfDay();
|
||||
int rc = iNow>=p->iCutoffTime;
|
||||
sqlite3_int64 iDiff = iNow - p->iLastCb;
|
||||
if( iDiff > p->mxInterval ) p->mxInterval = iDiff;
|
||||
p->nCb++;
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -54,12 +88,12 @@ static int exec_handler(void *pCnt, int argc, char **argv, char **namev){
|
|||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
int execCnt = 0; /* Abort row callback when count reaches zero */
|
||||
char *zErrMsg = 0; /* Error message returned by sqlite_exec() */
|
||||
sqlite3 *db; /* The database connection */
|
||||
uint8_t uSelector; /* First byte of input data[] */
|
||||
int rc; /* Return code from various interfaces */
|
||||
char *zSql; /* Zero-terminated copy of data[] */
|
||||
sqlite3_int64 iCutoff; /* Cutoff timer */
|
||||
FuzzCtx cx; /* Fuzzing context */
|
||||
|
||||
memset(&cx, 0, sizeof(cx));
|
||||
if( size<3 ) return 0; /* Early out if unsufficient data */
|
||||
|
||||
/* Extract the selector byte from the beginning of the input. But only
|
||||
|
@ -72,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
}
|
||||
|
||||
/* Open the database connection. Only use an in-memory database. */
|
||||
rc = sqlite3_open_v2("fuzz.db", &db,
|
||||
rc = sqlite3_open_v2("fuzz.db", &cx.db,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY, 0);
|
||||
if( rc ) return 0;
|
||||
|
||||
|
@ -82,12 +116,13 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
** (which will block further processing) if more than 10 seconds have
|
||||
** elapsed since the start of the test.
|
||||
*/
|
||||
iCutoff = timeOfDay() + 10000; /* Now + 10 seconds */
|
||||
sqlite3_progress_handler(db, 10, progress_handler, (void*)&iCutoff);
|
||||
cx.iLastCb = timeOfDay();
|
||||
cx.iCutoffTime = cx.iLastCb + 10000; /* Now + 10 seconds */
|
||||
sqlite3_progress_handler(cx.db, 10, progress_handler, (void*)&cx);
|
||||
#endif
|
||||
|
||||
/* Bit 1 of the selector enables foreign key constraints */
|
||||
sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, uSelector&1, &rc);
|
||||
sqlite3_db_config(cx.db, SQLITE_DBCONFIG_ENABLE_FKEY, uSelector&1, &rc);
|
||||
uSelector >>= 1;
|
||||
|
||||
/* Remaining bits of the selector determine a limit on the number of
|
||||
|
@ -97,11 +132,21 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
/* Run the SQL. The sqlite_exec() interface expects a zero-terminated
|
||||
** string, so make a copy. */
|
||||
zSql = sqlite3_mprintf("%.*s", (int)size, data);
|
||||
sqlite3_exec(db, zSql, exec_handler, (void*)&execCnt, &zErrMsg);
|
||||
sqlite3_exec(cx.db, zSql, exec_handler, (void*)&execCnt, &zErrMsg);
|
||||
|
||||
/* Show any errors */
|
||||
if( (mDebug & FUZZ_SHOW_ERRORS)!=0 && zErrMsg ){
|
||||
printf("Error: %s\n", zErrMsg);
|
||||
}
|
||||
|
||||
/* Cleanup and return */
|
||||
sqlite3_free(zErrMsg);
|
||||
sqlite3_free(zSql);
|
||||
sqlite3_close(db);
|
||||
sqlite3_close(cx.db);
|
||||
|
||||
if( mDebug & FUZZ_SHOW_MAX_DELAY ){
|
||||
printf("Progress callback count....... %d\n", cx.nCb);
|
||||
printf("Max time between callbacks.... %d ms\n", (int)cx.mxInterval);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*
|
||||
|
@ -16,6 +17,13 @@
|
|||
*/
|
||||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
|
||||
/* Must match equivalent #defines in ossfuzz.c */
|
||||
#define FUZZ_SQL_TRACE 0x0001 /* Set an sqlite3_trace() callback */
|
||||
#define FUZZ_SHOW_MAX_DELAY 0x0002 /* Show maximum progress callback delay */
|
||||
#define FUZZ_SHOW_ERRORS 0x0004 /* Show SQL errors */
|
||||
extern void ossfuzz_set_debug_flags(unsigned);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Read files named on the command-line and invoke the fuzzer for
|
||||
|
@ -27,9 +35,32 @@ int main(int argc, char **argv){
|
|||
int nErr = 0;
|
||||
uint8_t *zBuf = 0;
|
||||
size_t sz;
|
||||
unsigned mDebug = 0;
|
||||
|
||||
for(i=1; i<argc; i++){
|
||||
const char *zFilename = argv[i];
|
||||
if( zFilename[0]=='-' ){
|
||||
if( zFilename[1]=='-' ) zFilename++;
|
||||
if( strcmp(zFilename, "-show-errors")==0 ){
|
||||
mDebug |= FUZZ_SHOW_ERRORS;
|
||||
ossfuzz_set_debug_flags(mDebug);
|
||||
}else
|
||||
if( strcmp(zFilename, "-show-max-delay")==0 ){
|
||||
mDebug |= FUZZ_SHOW_MAX_DELAY;
|
||||
ossfuzz_set_debug_flags(mDebug);
|
||||
}else
|
||||
if( strcmp(zFilename, "-sql-trace")==0 ){
|
||||
mDebug |= FUZZ_SQL_TRACE;
|
||||
ossfuzz_set_debug_flags(mDebug);
|
||||
}else
|
||||
{
|
||||
printf("unknown option \"%s\"\n", argv[i]);
|
||||
printf("should be one of: --show-errors --show-max-delay"
|
||||
" --sql-trace\n");
|
||||
exit(1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
in = fopen(zFilename, "rb");
|
||||
if( in==0 ){
|
||||
fprintf(stderr, "cannot open \"%s\"\n", zFilename);
|
||||
|
@ -50,8 +81,10 @@ int main(int argc, char **argv){
|
|||
nErr++;
|
||||
}else{
|
||||
printf("%s... ", zFilename);
|
||||
if( mDebug ) printf("\n");
|
||||
fflush(stdout);
|
||||
(void)LLVMFuzzerTestOneInput(zBuf, sz);
|
||||
if( mDebug ) printf("%s: ", zFilename);
|
||||
printf("ok\n");
|
||||
}
|
||||
fclose(in);
|
||||
|
|
Loading…
Reference in New Issue