Various fixes and improvements to the --query-invariants option of
fuzzcheck. FossilOrigin-Name: 09aca89b7c26c1eb7f9df1d1cfdada18848d7c188fa7fbbcf95442dabce476ea
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
C Fix\sthe\snew\s--query-invariants\soption\son\sfuzzcheck\sso\sthat\sit\sdoes\snot\nuse\san\sunprotected\ssqlite3_value\sobject\sas\san\sargument\sto\ssqlite3_value_int64().
|
||||
D 2022-06-17T12:25:33.660
|
||||
C Various\sfixes\sand\simprovements\sto\sthe\s--query-invariants\soption\sof\nfuzzcheck.
|
||||
D 2022-06-17T16:39:55.788
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@@ -1085,7 +1085,7 @@ F test/fuzz3.test 9c813e6613b837cb7a277b0383cd66bfa07042b4cf0317157c35852f30043c
|
||||
F test/fuzz4.test c229bcdb45518a89e1d208a21343e061503460ac69fae1539320a89f572eb634
|
||||
F test/fuzz_common.tcl b7197de6ed1ee8250a4f82d67876f4561b42ee8cbbfc6160dcb66331bad3f830
|
||||
F test/fuzz_malloc.test f348276e732e814802e39f042b1f6da6362a610af73a528d8f76898fde6b22f2
|
||||
F test/fuzzcheck.c 609152902fb51e718554719f44d13677f68c53d98d15fb359fbefdd134be153b
|
||||
F test/fuzzcheck.c c50f105aaa5f5cc5ca5248ac8423ec316fbf6a9540236bcbf55999ff364bb49c
|
||||
F test/fuzzdata1.db 3e86d9cf5aea68ddb8e27c02d7dfdaa226347426c7eb814918e4d95475bf8517
|
||||
F test/fuzzdata2.db 128b3feeb78918d075c9b14b48610145a0dd4c8d6f1ca7c2870c7e425f5bf31f
|
||||
F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba
|
||||
@@ -1097,7 +1097,7 @@ F test/fuzzdata8.db ca9a97f401b06b0d5376139ec7e1f9e773e13345a9a2d9ccc0032cdbfede
|
||||
F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8
|
||||
F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14
|
||||
F test/fuzzerfault.test f64c4aef4c9e9edf1d6dc0d3f1e65dcc81e67c996403c88d14f09b74807a42bc
|
||||
F test/fuzzinvariants.c e7b413a2526d9f702a2bfea5cbe5bdb7cb88c89b433e3e8ad931888bb5597bd0
|
||||
F test/fuzzinvariants.c e1c844a9234329f8e6f84acc4c32c0657aacfde08d69d90cb9c24d332062994d
|
||||
F test/gcfault.test dd28c228a38976d6336a3fc42d7e5f1ad060cb8c
|
||||
F test/gencol1.test cc0dbb0ee116e5602e18ea7d47f2a0f76b26e09a823b7c36ef254370c2b0f3c1
|
||||
F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98
|
||||
@@ -1978,8 +1978,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P f23a429d4153518d37387e121f22a30b22e2b31e126ad168e72049a96be86269
|
||||
R 10f66102aac19f279bc67099d1ccf16a
|
||||
P d9f820151d74a690b5fa560597a5b3ace20165a112e1b58cb4a7c47b42745643 0fe2e465ba931d4bceaf171693d2ee7af45a5f96840e65e9d4ee4a2e60f155d8
|
||||
R a7fd0f7a55560bceea65dad05280da0e
|
||||
T +closed 0fe2e465ba931d4bceaf171693d2ee7af45a5f96840e65e9d4ee4a2e60f155d8
|
||||
U drh
|
||||
Z 8cec7a3e8591667bdea33d0479acc5f3
|
||||
Z c4d513a0fe34cc5ee401eef54d4b01ee
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
d9f820151d74a690b5fa560597a5b3ace20165a112e1b58cb4a7c47b42745643
|
||||
09aca89b7c26c1eb7f9df1d1cfdada18848d7c188fa7fbbcf95442dabce476ea
|
||||
+38
-21
@@ -896,9 +896,17 @@ static int block_troublesome_sql(
|
||||
}
|
||||
case SQLITE_FUNCTION: {
|
||||
static const char *azBadFuncs[] = {
|
||||
"current_date",
|
||||
"current_time",
|
||||
"current_timestamp",
|
||||
"date",
|
||||
"datetime",
|
||||
"julianday",
|
||||
"random",
|
||||
"randomblob",
|
||||
"rtreedepth",
|
||||
"strftime",
|
||||
"time",
|
||||
"unixepoch",
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(azBadFuncs)/sizeof(azBadFuncs[0]); i++){
|
||||
@@ -926,6 +934,7 @@ int fuzz_invariant(
|
||||
sqlite3_stmt *pStmt, /* Test statement stopped on an SQLITE_ROW */
|
||||
int iCnt, /* Invariant sequence number, starting at 0 */
|
||||
int iRow, /* The row number for pStmt */
|
||||
int nRow, /* Total number of output rows */
|
||||
int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */
|
||||
int eVerbosity /* How much debugging output */
|
||||
);
|
||||
@@ -949,25 +958,7 @@ static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){
|
||||
int nRow = 0;
|
||||
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
|
||||
nRow++;
|
||||
if( (*pBtsFlags)==BTS_SELECT
|
||||
&& g.doInvariantChecks
|
||||
&& !sqlite3_stmt_isexplain(pStmt)
|
||||
){
|
||||
int iCnt = 0;
|
||||
for(iCnt=0; iCnt<99999; iCnt++){
|
||||
rc = fuzz_invariant(db, pStmt, iCnt, nRow, &bCorrupt, eVerbosity);
|
||||
if( rc==SQLITE_DONE ) break;
|
||||
if( rc!=SQLITE_ERROR ) g.nInvariant++;
|
||||
if( eVerbosity>0 ){
|
||||
if( rc==SQLITE_OK ){
|
||||
printf("invariant-check: ok\n");
|
||||
}else if( rc==SQLITE_CORRUPT ){
|
||||
printf("invariant-check: failed due to database corruption\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( eVerbosity>=5 ){
|
||||
if( eVerbosity>=4 ){
|
||||
int j;
|
||||
for(j=0; j<sqlite3_column_count(pStmt); j++){
|
||||
if( j ) printf(",");
|
||||
@@ -1015,7 +1006,33 @@ static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){
|
||||
fflush(stdout);
|
||||
} /* End if( eVerbosity>=5 ) */
|
||||
} /* End while( SQLITE_ROW */
|
||||
if( rc!=SQLITE_DONE && eVerbosity>=4 ){
|
||||
if( rc==SQLITE_DONE ){
|
||||
if( (*pBtsFlags)==BTS_SELECT
|
||||
&& g.doInvariantChecks
|
||||
&& !sqlite3_stmt_isexplain(pStmt)
|
||||
&& nRow>0
|
||||
){
|
||||
int iRow = 0;
|
||||
sqlite3_reset(pStmt);
|
||||
while( sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
int iCnt = 0;
|
||||
iRow++;
|
||||
for(iCnt=0; iCnt<99999; iCnt++){
|
||||
rc = fuzz_invariant(db, pStmt, iCnt, iRow, nRow,
|
||||
&bCorrupt, eVerbosity);
|
||||
if( rc==SQLITE_DONE ) break;
|
||||
if( rc!=SQLITE_ERROR ) g.nInvariant++;
|
||||
if( eVerbosity>0 ){
|
||||
if( rc==SQLITE_OK ){
|
||||
printf("invariant-check: ok\n");
|
||||
}else if( rc==SQLITE_CORRUPT ){
|
||||
printf("invariant-check: failed due to database corruption\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if( eVerbosity>=4 ){
|
||||
printf("SQL-ERROR: (%d) %s\n", rc, sqlite3_errmsg(db));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
+29
-13
@@ -62,7 +62,8 @@ int fuzz_invariant(
|
||||
sqlite3 *db, /* The database connection */
|
||||
sqlite3_stmt *pStmt, /* Test statement stopped on an SQLITE_ROW */
|
||||
int iCnt, /* Invariant sequence number, starting at 0 */
|
||||
int iRow, /* The row number for pStmt */
|
||||
int iRow, /* Current row number */
|
||||
int nRow, /* Number of output rows from pStmt */
|
||||
int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */
|
||||
int eVerbosity /* How much debugging output */
|
||||
){
|
||||
@@ -71,8 +72,11 @@ int fuzz_invariant(
|
||||
int rc;
|
||||
int i;
|
||||
int nCol;
|
||||
int nParam;
|
||||
|
||||
if( *pbCorrupt ) return SQLITE_DONE;
|
||||
nParam = sqlite3_bind_parameter_count(pStmt);
|
||||
if( nParam>100 ) return SQLITE_DONE;
|
||||
zTest = fuzz_invariant_sql(pStmt, iCnt);
|
||||
if( zTest==0 ) return SQLITE_DONE;
|
||||
rc = sqlite3_prepare_v2(db, zTest, -1, &pTestStmt, 0);
|
||||
@@ -88,7 +92,7 @@ int fuzz_invariant(
|
||||
sqlite3_free(zTest);
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
for(i=0; i<nCol; i++){
|
||||
sqlite3_bind_value(pTestStmt, i+1, sqlite3_column_value(pStmt,i));
|
||||
sqlite3_bind_value(pTestStmt, i+1+nParam, sqlite3_column_value(pStmt,i));
|
||||
}
|
||||
if( eVerbosity>=2 ){
|
||||
char *zSql = sqlite3_expanded_sql(pTestStmt);
|
||||
@@ -101,7 +105,7 @@ int fuzz_invariant(
|
||||
}
|
||||
if( i>=nCol ) break;
|
||||
}
|
||||
if( rc!=SQLITE_ROW ){
|
||||
if( rc!=SQLITE_ROW && rc!=SQLITE_NOMEM ){
|
||||
/* No matching output row found */
|
||||
sqlite3_stmt *pCk = 0;
|
||||
rc = sqlite3_prepare_v2(db, "PRAGMA integrity_check", -1, &pCk, 0);
|
||||
@@ -123,7 +127,10 @@ int fuzz_invariant(
|
||||
sqlite3_finalize(pCk);
|
||||
rc = sqlite3_prepare_v2(db,
|
||||
"SELECT 1 FROM bytecode(?1) WHERE opcode='VOpen'", -1, &pCk, 0);
|
||||
if( rc==SQLITE_OK ) rc = sqlite3_step(pCk);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_bind_pointer(pCk, 1, pStmt, "stmt-pointer", 0);
|
||||
rc = sqlite3_step(pCk);
|
||||
}
|
||||
sqlite3_finalize(pCk);
|
||||
if( rc==SQLITE_DONE ){
|
||||
reportInvariantFailed(pStmt, pTestStmt, iRow);
|
||||
@@ -155,18 +162,16 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
|
||||
int mxCnt;
|
||||
int bDistinct = 0;
|
||||
int bOrderBy = 0;
|
||||
int nParam = sqlite3_bind_parameter_count(pStmt);
|
||||
|
||||
iCnt++;
|
||||
switch( iCnt % 4 ){
|
||||
case 1: bDistinct = 1; break;
|
||||
case 2: bOrderBy = 1; break;
|
||||
case 3: bDistinct = bOrderBy = 1; break;
|
||||
}
|
||||
iCnt /= 4;
|
||||
if( nCol==1 ){
|
||||
mxCnt = 0;
|
||||
}else{
|
||||
mxCnt = nCol;
|
||||
}
|
||||
mxCnt = nCol;
|
||||
if( iCnt<0 || iCnt>mxCnt ) return 0;
|
||||
zIn = sqlite3_sql(pStmt);
|
||||
if( zIn==0 ) return 0;
|
||||
@@ -192,11 +197,12 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
|
||||
** WHERE clause. */
|
||||
continue;
|
||||
}
|
||||
if( iCnt>0 && i+1!=iCnt ) continue;
|
||||
if( i+1!=iCnt ) continue;
|
||||
if( sqlite3_column_type(pStmt, i)==SQLITE_NULL ){
|
||||
sqlite3_str_appendf(pTest, " %s \"%w\" ISNULL", zAnd, zColName);
|
||||
}else{
|
||||
sqlite3_str_appendf(pTest, " %s \"%w\"=?%d", zAnd, zColName, i+1);
|
||||
sqlite3_str_appendf(pTest, " %s \"%w\"=?%d", zAnd, zColName,
|
||||
i+1+nParam);
|
||||
}
|
||||
zAnd = "AND";
|
||||
}
|
||||
@@ -212,7 +218,17 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
|
||||
*/
|
||||
static int sameValue(sqlite3_stmt *pS1, int i1, sqlite3_stmt *pS2, int i2){
|
||||
int x = 1;
|
||||
if( sqlite3_column_type(pS1,i1)!=sqlite3_column_type(pS2,i2) ) return 0;
|
||||
int t1 = sqlite3_column_type(pS1,i1);
|
||||
int t2 = sqlite3_column_type(pS2,i2);
|
||||
if( t1!=t2 ){
|
||||
if( (t1==SQLITE_INTEGER && t2==SQLITE_FLOAT)
|
||||
|| (t1==SQLITE_FLOAT && t2==SQLITE_INTEGER)
|
||||
){
|
||||
/* Comparison of numerics is ok */
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
switch( sqlite3_column_type(pS1,i1) ){
|
||||
case SQLITE_INTEGER: {
|
||||
x = sqlite3_column_int64(pS1,i1)==sqlite3_column_int64(pS2,i2);
|
||||
@@ -253,7 +269,7 @@ static void printRow(sqlite3_stmt *pStmt, int iRow){
|
||||
int i, nCol;
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
for(i=0; i<nCol; i++){
|
||||
printf("row%d.col%d] = ", iRow, i);
|
||||
printf("row%d.col%d = ", iRow, i);
|
||||
switch( sqlite3_column_type(pStmt, i) ){
|
||||
case SQLITE_NULL: {
|
||||
printf("NULL\n");
|
||||
|
||||
Reference in New Issue
Block a user