/ Check-in [004f7d9b]
Login

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

Overview
Comment:Update fuzzcheck so that with the --load-dbsql options it screens its inputs to ensure that they are valid dbsqlfuzz cases. Add new dbsqlfuzz finds to the test/fuzzdata8.db database.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:004f7d9bbeee049c22a7e1c82c6cc0ea79a237967de3ff57686acea3060d5f45
User & Date: drh 2019-01-27 01:11:40
Context
2019-01-27
02:41
Window functions that can abort should indicate this, so that if they are used in DML statement, a statement journal will be used. check-in: 0ea05a0e user: drh tags: trunk
01:11
Update fuzzcheck so that with the --load-dbsql options it screens its inputs to ensure that they are valid dbsqlfuzz cases. Add new dbsqlfuzz finds to the test/fuzzdata8.db database. check-in: 004f7d9b user: drh tags: trunk
2019-01-26
23:34
Ensure that the btree cursor is correctly set up prior to backing it up as part of a delete operation on a divider cell in an index. check-in: a3ea1a82 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/fuzzcheck.c.

   866    866     for(i=0; n>0 && i<8; n--, a++){
   867    867       if( isxdigit(a[0]) ) buf[i++] = a[0];
   868    868     }
   869    869     if( i==8 && memcmp(buf,"53514c69",8)==0 ) return 1;
   870    870     return 0;
   871    871   }
   872    872   
          873  +/* Implementation of the isdbsql(TEXT) SQL function.
          874  +*/
          875  +static void isDbSqlFunc(
          876  +  sqlite3_context *context,
          877  +  int argc,
          878  +  sqlite3_value **argv
          879  +){
          880  +  int n = sqlite3_value_bytes(argv[0]);
          881  +  unsigned char *a = (unsigned char*)sqlite3_value_blob(argv[0]);
          882  +  sqlite3_result_int(context, a!=0 && n>0 && isDbSql(a,n));
          883  +}
   873    884   
   874    885   /* Methods for the VHandle object
   875    886   */
   876    887   static int inmemClose(sqlite3_file *pFile){
   877    888     VHandle *p = (VHandle*)pFile;
   878    889     VFile *pVFile = p->pVFile;
   879    890     pVFile->nRef--;
................................................................................
  1165   1176   /*
  1166   1177   ** Rebuild the database file.
  1167   1178   **
  1168   1179   **    (1)  Remove duplicate entries
  1169   1180   **    (2)  Put all entries in order
  1170   1181   **    (3)  Vacuum
  1171   1182   */
  1172         -static void rebuild_database(sqlite3 *db){
         1183  +static void rebuild_database(sqlite3 *db, int dbSqlOnly){
  1173   1184     int rc;
  1174         -  rc = sqlite3_exec(db, 
         1185  +  char *zSql;
         1186  +  zSql = sqlite3_mprintf(
  1175   1187        "BEGIN;\n"
  1176   1188        "CREATE TEMP TABLE dbx AS SELECT DISTINCT dbcontent FROM db;\n"
  1177   1189        "DELETE FROM db;\n"
  1178   1190        "INSERT INTO db(dbid, dbcontent) "
  1179   1191           " SELECT NULL, dbcontent FROM dbx ORDER BY 2;\n"
  1180   1192        "DROP TABLE dbx;\n"
  1181         -     "CREATE TEMP TABLE sx AS SELECT DISTINCT sqltext FROM xsql;\n"
         1193  +     "CREATE TEMP TABLE sx AS SELECT DISTINCT sqltext FROM xsql %s;\n"
  1182   1194        "DELETE FROM xsql;\n"
  1183   1195        "INSERT INTO xsql(sqlid,sqltext) "
  1184   1196           " SELECT NULL, sqltext FROM sx ORDER BY 2;\n"
  1185   1197        "DROP TABLE sx;\n"
  1186   1198        "COMMIT;\n"
  1187   1199        "PRAGMA page_size=1024;\n"
  1188         -     "VACUUM;\n", 0, 0, 0);
         1200  +     "VACUUM;\n",
         1201  +     dbSqlOnly ? " WHERE isdbsql(sqltext)" : ""
         1202  +  );
         1203  +  rc = sqlite3_exec(db, zSql, 0, 0, 0);
         1204  +  sqlite3_free(zSql);
  1189   1205     if( rc ) fatalError("cannot rebuild: %s", sqlite3_errmsg(db));
  1190   1206   }
  1191   1207   
  1192   1208   /*
  1193   1209   ** Return the value of a hexadecimal digit.  Return -1 if the input
  1194   1210   ** is not a hex digit.
  1195   1211   */
................................................................................
  1275   1291   "  --export-sql DIR     Write SQL to file(s) in DIR. Also works with --sqlid\n"
  1276   1292   "  --help               Show this help text\n"
  1277   1293   "  --info               Show information about SOURCE-DB w/o running tests\n"
  1278   1294   "  --limit-mem N        Limit memory used by test SQLite instance to N bytes\n"
  1279   1295   "  --limit-vdbe         Panic if any test runs for more than 100,000 cycles\n"
  1280   1296   "  --load-sql ARGS...   Load SQL scripts fron files into SOURCE-DB\n"
  1281   1297   "  --load-db ARGS...    Load template databases from files into SOURCE_DB\n"
         1298  +"  --load-dbsql ARGS..  Load dbsqlfuzz outputs into the xsql table\n"
  1282   1299   "  -m TEXT              Add a description to the database\n"
  1283   1300   "  --native-vfs         Use the native VFS for initially empty database files\n"
  1284   1301   "  --native-malloc      Turn off MEMSYS3/5 and Lookaside\n"
  1285   1302   "  --oss-fuzz           Enable OSS-FUZZ testing\n"
  1286   1303   "  --prng-seed N        Seed value for the PRGN inside of SQLite\n"
  1287   1304   "  -q|--quiet           Reduced output\n"
  1288   1305   "  --rebuild            Rebuild and vacuum the database file\n"
................................................................................
  1301   1318     int iFirstInsArg = 0;        /* First argv[] for --load-db or --load-sql */
  1302   1319     sqlite3 *db = 0;             /* The open database connection */
  1303   1320     sqlite3_stmt *pStmt;         /* A prepared statement */
  1304   1321     int rc;                      /* Result code from SQLite interface calls */
  1305   1322     Blob *pSql;                  /* For looping over SQL scripts */
  1306   1323     Blob *pDb;                   /* For looping over template databases */
  1307   1324     int i;                       /* Loop index for the argv[] loop */
         1325  +  int dbSqlOnly = 0;           /* Only use scripts that are dbsqlfuzz */
  1308   1326     int onlySqlid = -1;          /* --sqlid */
  1309   1327     int onlyDbid = -1;           /* --dbid */
  1310   1328     int nativeFlag = 0;          /* --native-vfs */
  1311   1329     int rebuildFlag = 0;         /* --rebuild */
  1312   1330     int vdbeLimitFlag = 0;       /* --limit-vdbe */
  1313   1331     int infoFlag = 0;            /* --info */
  1314   1332     int timeoutTest = 0;         /* undocumented --timeout-test flag */
................................................................................
  1357   1375           if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
  1358   1376           onlyDbid = integerValue(argv[++i]);
  1359   1377         }else
  1360   1378         if( strcmp(z,"export-db")==0 ){
  1361   1379           if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
  1362   1380           zExpDb = argv[++i];
  1363   1381         }else
  1364         -      if( strcmp(z,"export-sql")==0 ){
         1382  +      if( strcmp(z,"export-sql")==0 || strcmp(z,"export-dbsql")==0 ){
  1365   1383           if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
  1366   1384           zExpSql = argv[++i];
  1367   1385         }else
  1368   1386         if( strcmp(z,"help")==0 ){
  1369   1387           showHelp();
  1370   1388           return 0;
  1371   1389         }else
................................................................................
  1391   1409           break;
  1392   1410         }else
  1393   1411         if( strcmp(z,"load-db")==0 ){
  1394   1412           zInsSql = "INSERT INTO db(dbcontent) VALUES(readfile(?1))";
  1395   1413           iFirstInsArg = i+1;
  1396   1414           openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
  1397   1415           break;
         1416  +      }else
         1417  +      if( strcmp(z,"load-dbsql")==0 ){
         1418  +        zInsSql = "INSERT INTO xsql(sqltext)VALUES(CAST(readfile(?1) AS text))";
         1419  +        iFirstInsArg = i+1;
         1420  +        openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
         1421  +        dbSqlOnly = 1;
         1422  +        break;
  1398   1423         }else
  1399   1424         if( strcmp(z,"m")==0 ){
  1400   1425           if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
  1401   1426           zMsg = argv[++i];
  1402   1427           openFlags4Data = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
  1403   1428         }else
  1404   1429         if( strcmp(z,"native-malloc")==0 ){
................................................................................
  1573   1598         }
  1574   1599         sqlite3_finalize(pStmt);
  1575   1600       }
  1576   1601   
  1577   1602       if( zInsSql ){
  1578   1603         sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
  1579   1604                                 readfileFunc, 0, 0);
         1605  +      sqlite3_create_function(db, "isdbsql", 1, SQLITE_UTF8, 0,
         1606  +                              isDbSqlFunc, 0, 0);
  1580   1607         rc = sqlite3_prepare_v2(db, zInsSql, -1, &pStmt, 0);
  1581   1608         if( rc ) fatalError("cannot prepare statement [%s]: %s",
  1582   1609                             zInsSql, sqlite3_errmsg(db));
  1583   1610         rc = sqlite3_exec(db, "BEGIN", 0, 0, 0);
  1584   1611         if( rc ) fatalError("cannot start a transaction");
  1585   1612         for(i=iFirstInsArg; i<argc; i++){
  1586   1613           sqlite3_bind_text(pStmt, 1, argv[i], -1, SQLITE_STATIC);
................................................................................
  1588   1615           rc = sqlite3_reset(pStmt);
  1589   1616           if( rc ) fatalError("insert failed for %s", argv[i]);
  1590   1617         }
  1591   1618         sqlite3_finalize(pStmt);
  1592   1619         rc = sqlite3_exec(db, "COMMIT", 0, 0, 0);
  1593   1620         if( rc ) fatalError("cannot commit the transaction: %s",
  1594   1621                             sqlite3_errmsg(db));
  1595         -      rebuild_database(db);
         1622  +      rebuild_database(db, dbSqlOnly);
  1596   1623         sqlite3_close(db);
  1597   1624         return 0;
  1598   1625       }
  1599   1626       rc = sqlite3_exec(db, "PRAGMA query_only=1;", 0, 0, 0);
  1600   1627       if( rc ) fatalError("cannot set database to query-only");
  1601   1628       if( zExpDb!=0 || zExpSql!=0 ){
  1602   1629         sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
................................................................................
  1675   1702   
  1676   1703       /* Rebuild the database, if requested */
  1677   1704       if( rebuildFlag ){
  1678   1705         if( !quietFlag ){
  1679   1706           printf("%s: rebuilding... ", zDbName);
  1680   1707           fflush(stdout);
  1681   1708         }
  1682         -      rebuild_database(db);
         1709  +      rebuild_database(db, 0);
  1683   1710         if( !quietFlag ) printf("done\n");
  1684   1711       }
  1685   1712     
  1686   1713       /* Close the source database.  Verify that no SQLite memory allocations are
  1687   1714       ** outstanding.
  1688   1715       */
  1689   1716       sqlite3_close(db);

Changes to test/fuzzdata8.db.

cannot compute difference between binary files