SQLite

Check-in [8b77d3953f]
Login

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

Overview
Comment:Further fuzzer test cases. Fix a case in the fuzzer where an error code was being dropped.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8b77d3953f082e6fa42e42fe903ea9eddf99dd91
User & Date: dan 2012-02-21 14:11:12.123
Context
2012-02-21
18:00
Prevent the fuzzer from ever returning a string longer than 100 bytes. (check-in: 969095ca30 user: dan tags: trunk)
14:11
Further fuzzer test cases. Fix a case in the fuzzer where an error code was being dropped. (check-in: 8b77d3953f user: dan tags: trunk)
10:36
Add further test cases and minor fixes for the fuzzer. (check-in: 583dde93a9 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/test_fuzzer.c.
528
529
530
531
532
533
534
535
536


537
538
539
540
541
542
543
        rc = SQLITE_NOMEM;
      }else{
        rc = fuzzerLoadRules(db, pNew, zDb, zTab, pzErr);
        sqlite3_free(zTab);
      }

      if( rc==SQLITE_OK ){
        sqlite3_declare_vtab(db, "CREATE TABLE x(word, distance, ruleset)");
      }else{


        fuzzerDisconnect((sqlite3_vtab *)pNew);
        pNew = 0;
      }
    }
  }

  *ppVtab = (sqlite3_vtab *)pNew;







|
<
>
>







528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
543
544
        rc = SQLITE_NOMEM;
      }else{
        rc = fuzzerLoadRules(db, pNew, zDb, zTab, pzErr);
        sqlite3_free(zTab);
      }

      if( rc==SQLITE_OK ){
        rc = sqlite3_declare_vtab(db, "CREATE TABLE x(word,distance,ruleset)");

      }
      if( rc!=SQLITE_OK ){
        fuzzerDisconnect((sqlite3_vtab *)pNew);
        pNew = 0;
      }
    }
  }

  *ppVtab = (sqlite3_vtab *)pNew;
Changes to test/fuzzer1.test.
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719













































































































1720
1721
  SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10;
} {xx hw hx hy hz ia ib ic id ie}
do_execsql_test 6.2.2 {
  SELECT cTo FROM x1_rules WHERE cFrom='xx' 
  ORDER BY cost asc, rowid asc LIMIT 9;
} {hw hx hy hz ia ib ic id ie}


#-------------------------------------------------------------------------
# Test using different types of quotes with CREATE VIRTUAL TABLE 
# arguments.
#
do_execsql_test 7.1 {
  CREATE TABLE [x2 "rules] (a, b, c, d);
  INSERT INTO [x2 "rules] VALUES(0, 'a', 'b', 5);
}
foreach {tn sql} {
  1 { CREATE VIRTUAL TABLE x2 USING fuzzer( [x2 "rules] ) }
  2 { CREATE VIRTUAL TABLE x2 USING fuzzer( "x2 ""rules" ) }
  3 { CREATE VIRTUAL TABLE x2 USING fuzzer( 'x2 "rules' ) }
  4 { CREATE VIRTUAL TABLE x2 USING fuzzer( `x2 "rules` ) }
} {
  do_execsql_test 7.2.$tn.1 { DROP TABLE IF EXISTS x2 }
  do_execsql_test 7.2.$tn.2 $sql
  do_execsql_test 7.2.$tn.3 { 
    SELECT word FROM x2 WHERE word MATCH 'aaa' 
  } {aaa baa aba aab bab abb bba bbb}
}














































































































finish_test








<





















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1691
1692
1693
1694
1695
1696
1697

1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
  SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10;
} {xx hw hx hy hz ia ib ic id ie}
do_execsql_test 6.2.2 {
  SELECT cTo FROM x1_rules WHERE cFrom='xx' 
  ORDER BY cost asc, rowid asc LIMIT 9;
} {hw hx hy hz ia ib ic id ie}


#-------------------------------------------------------------------------
# Test using different types of quotes with CREATE VIRTUAL TABLE 
# arguments.
#
do_execsql_test 7.1 {
  CREATE TABLE [x2 "rules] (a, b, c, d);
  INSERT INTO [x2 "rules] VALUES(0, 'a', 'b', 5);
}
foreach {tn sql} {
  1 { CREATE VIRTUAL TABLE x2 USING fuzzer( [x2 "rules] ) }
  2 { CREATE VIRTUAL TABLE x2 USING fuzzer( "x2 ""rules" ) }
  3 { CREATE VIRTUAL TABLE x2 USING fuzzer( 'x2 "rules' ) }
  4 { CREATE VIRTUAL TABLE x2 USING fuzzer( `x2 "rules` ) }
} {
  do_execsql_test 7.2.$tn.1 { DROP TABLE IF EXISTS x2 }
  do_execsql_test 7.2.$tn.2 $sql
  do_execsql_test 7.2.$tn.3 { 
    SELECT word FROM x2 WHERE word MATCH 'aaa' 
  } {aaa baa aba aab bab abb bba bbb}
}

#-------------------------------------------------------------------------
# Test using a fuzzer table in different contexts.
#
do_execsql_test 8.1 {
  CREATE TABLE x3_rules(rule_set, cFrom, cTo, cost);
  INSERT INTO x3_rules VALUES(2, 'a', 'x', 10);
  INSERT INTO x3_rules VALUES(2, 'a', 'y',  9);
  INSERT INTO x3_rules VALUES(2, 'a', 'z',  8);
  CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules);
}

do_execsql_test 8.2.1 {
  SELECT cFrom, cTo, word 
    FROM x3_rules CROSS JOIN x3 
    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
} {a x x a y y a z z}

do_execsql_test 8.2.2 {
  SELECT cFrom, cTo, word 
    FROM x3 CROSS JOIN x3_rules
    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
} {a z z a y y a x x}

do_execsql_test 8.2.3 {
  SELECT cFrom, cTo, word 
    FROM x3_rules, x3 
    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
} {a z z a y y a x x}

do_execsql_test 8.2.4 {
  SELECT cFrom, cTo, word 
    FROM x3, x3_rules
    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
} {a z z a y y a x x}

do_execsql_test 8.2.5 {
  CREATE INDEX i1 ON x3_rules(cost);
  SELECT cFrom, cTo, word 
    FROM x3_rules, x3 
    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
} {a z z a y y a x x}

do_execsql_test 8.2.5 {
  SELECT word FROM x3_rules, x3 WHERE word MATCH x3_rules.cFrom AND ruleset=2;
} {a z y x a z y x a z y x}

do_execsql_test 8.2.6 {
  SELECT word FROM x3_rules, x3 
  WHERE word MATCH x3_rules.cFrom 
    AND ruleset=2 
    AND x3_rules.cost=8;
} {a z y x}

do_execsql_test 8.2.7 {
  CREATE TABLE t1(a, b);
  CREATE INDEX i2 ON t1(b);
  SELECT word, distance FROM x3, t1 
    WHERE x3.word MATCH t1.a AND ruleset=2 AND distance=t1.b;
} {}

do_execsql_test 8.2.8 {
  INSERT INTO x3_rules VALUES(1, 'a', 't',  5);
  INSERT INTO x3_rules VALUES(1, 'a', 'u',  4);
  INSERT INTO x3_rules VALUES(1, 'a', 'v',  3);
  DROP TABLE x3;
  CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules);
  SELECT * FROM x3_rules;
} {
  2 a x 10 
  2 a y 9 
  2 a z 8 
  1 a t 5 
  1 a u 4 
  1 a v 3
}

do_catchsql_test 8.2.9 {
  SELECT word FROM x3 WHERE ruleset=2 AND word MATCH 'a' AND WORD MATCH 'b';
} {1 {unable to use function MATCH in the requested context}}

do_execsql_test 8.2.10 {
  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a'
} {a v u t}

# The term "ruleset<=1" is not handled by the fuzzer module. Instead, it
# is handled by SQLite, which assumes that all rows have a NULL value in
# the ruleset column. Since NULL<=1 is never true, this query returns
# no rows.
do_execsql_test 8.2.11 {
  SELECT word FROM x3 WHERE ruleset<=1 AND word MATCH 'a'
} {}

do_execsql_test 8.2.12 {
  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance ASC;
} {a v u t}

do_execsql_test 8.2.13 {
  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance DESC;
} {t u v a}

do_execsql_test 8.2.13 {
  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word ASC;
} {a t u v}

do_execsql_test 8.2.14 {
  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word DESC;
} {v u t a}


finish_test

Added test/fuzzerfault.test.






























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 2012 February 21
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for TCL interface to the
# SQLite library. 
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !vtab { finish_test ; return }
set ::testprefix fuzzerfault

register_fuzzer_module db

do_test 1-pre1 {
  execsql {
    CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost);
    INSERT INTO x1_rules VALUES(0, 'a', 'b', 1);
    INSERT INTO x1_rules VALUES(0, 'a', 'c', 2);
    INSERT INTO x1_rules VALUES(0, 'a', 'd', 3);
  }
  faultsim_save_and_close
} {}

do_faultsim_test 1 -faults oom-t* -prep {
  faultsim_restore_and_reopen
  register_fuzzer_module db
} -body {
  execsql { 
    CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules);
    SELECT word FROM x1 WHERE word MATCH 'xax';
  }
} -test {
  faultsim_test_result {0 {xax xbx xcx xdx}}               \
                       {1 {vtable constructor failed: x1}}
}



finish_test