/ Check-in [d2282e64]
Login

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

Overview
Comment:Extend out-of-memory testing with fuzzily generated sql some. One fix for a problem found by the same. (CVS 4044)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d2282e64f1320913797dfb4dae4db0428a15a200
User & Date: danielk1977 2007-05-31 08:20:44
Context
2007-06-02
07:54
Fix a vdbe stack leak that could occur where one side of a WHERE clause inequality evaluated to SQL null. (CVS 4045) check-in: 17152bf1 user: danielk1977 tags: trunk
2007-05-31
08:20
Extend out-of-memory testing with fuzzily generated sql some. One fix for a problem found by the same. (CVS 4044) check-in: d2282e64 user: danielk1977 tags: trunk
2007-05-30
10:36
Add some extra tests for malloc failure during expression parsing and execution using fuzzily generated SQL. (CVS 4043) check-in: 7522d2fb user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.348 2007/05/14 16:50:49 danielk1977 Exp $
           15  +** $Id: select.c,v 1.349 2007/05/31 08:20:44 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
  2645   2645     }
  2646   2646     if( p->pPrior==0 ){
  2647   2647       if( processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") ||
  2648   2648           processOrderGroupBy(&sNC, pGroupBy, "GROUP") ){
  2649   2649         return SQLITE_ERROR;
  2650   2650       }
  2651   2651     }
         2652  +
         2653  +  if( sqlite3MallocFailed() ){
         2654  +    return SQLITE_NOMEM;
         2655  +  }
  2652   2656   
  2653   2657     /* Make sure the GROUP BY clause does not contain aggregate functions.
  2654   2658     */
  2655   2659     if( pGroupBy ){
  2656   2660       struct ExprList_item *pItem;
  2657   2661     
  2658   2662       for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){

Changes to test/fuzz_malloc.test.

     8      8   #    May you find forgiveness for yourself and forgive others.
     9      9   #    May you share freely, never taking more than you give.
    10     10   #
    11     11   #***********************************************************************
    12     12   #
    13     13   # This file tests malloc failures in concert with fuzzy SQL generation.
    14     14   #
    15         -# $Id: fuzz_malloc.test,v 1.1 2007/05/30 10:36:47 danielk1977 Exp $
           15  +# $Id: fuzz_malloc.test,v 1.2 2007/05/31 08:20:44 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   source $testdir/fuzz_common.tcl
    20     20   source $testdir/malloc_common.tcl
    21     21   
    22     22   set ::REPEATS 20
    23     23   
    24     24   #
    25     25   # Usage: do_fuzzy_malloc_test <testname> ?<options>?
    26     26   # 
    27     27   #     -template
           28  +#     -sqlprep
    28     29   #     -repeats
    29     30   #     
    30     31   proc do_fuzzy_malloc_test {testname args} {
    31     32     set ::fuzzyopts(-repeats) $::REPEATS
           33  +  set ::fuzzyopts(-sqlprep) {}
    32     34     array set ::fuzzyopts $args
           35  +
           36  +  sqlite_malloc_fail 0
           37  +  db close
           38  +  file delete test.db test.db-journal
           39  +  sqlite3 db test.db
           40  +  set ::prep $::fuzzyopts(-sqlprep)
           41  +  execsql $::prep
    33     42   
    34     43     for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
    35     44       set ::sql [subst $::fuzzyopts(-template)]
    36         -    # puts $::sql
    37         -    foreach {rc res} [catchsql $::sql] {}
           45  +    foreach {rc res} [catchsql "$::sql"] {}
    38     46       if {$rc==0} {
    39         -      do_malloc_test $testname-$ii -sqlbody $::sql
           47  +      do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
    40     48       } else {
    41     49         incr ii -1
    42     50       }
    43     51     }
    44     52   }
    45     53   
    46     54   #----------------------------------------------------------------
    47     55   # Test malloc failure during parsing (and execution) of a fuzzily 
    48     56   # generated expressions.
    49     57   #
    50     58   do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
           59  +do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
           60  +
           61  +set ::SQLPREP {
           62  +  BEGIN;
           63  +    CREATE TABLE abc(a, b, c);
           64  +    CREATE TABLE def(a, b, c);
           65  +    CREATE TABLE ghi(a, b, c);
           66  +    INSERT INTO abc VALUES(1.5, 3, 'a short string');
           67  +    INSERT INTO def VALUES(NULL, X'ABCDEF', 
           68  +        'a longer string. Long enough that it doesn''t fit in Mem.zShort');
           69  +    INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
           70  +  COMMIT;
           71  +}
           72  +set ::TableList  [list abc def ghi]
           73  +set ::ColumnList [list a b c]
           74  +
           75  +do_fuzzy_malloc_test fuzzy_malloc-3 \
           76  +  -template {[Select]}              \
           77  +  -sqlprep $::SQLPREP
    51     78   
    52     79   sqlite_malloc_fail 0
    53     80   finish_test
           81  +

Changes to test/mallocB.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file contains additional out-of-memory checks (see malloc.tcl).
    12     12   # These were all discovered by fuzzy generation of SQL. Apart from
    13     13   # that they have little in common.
    14     14   #
    15         -# $Id: mallocB.test,v 1.1 2007/05/30 10:36:47 danielk1977 Exp $
           15  +# $Id: mallocB.test,v 1.2 2007/05/31 08:20:44 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   source $testdir/malloc_common.tcl
    20     20   
    21     21   # Only run these tests if memory debugging is turned on.
    22     22   #
................................................................................
    26     26      return
    27     27   }
    28     28   
    29     29   do_malloc_test mallocB-1 -sqlbody {SELECT - 456}
    30     30   do_malloc_test mallocB-2 -sqlbody {SELECT - 456.1}
    31     31   do_malloc_test mallocB-3 -sqlbody {SELECT random()}
    32     32   do_malloc_test mallocB-4 -sqlbody {SELECT zeroblob(1000)}
           33  +do_malloc_test mallocB-5 -sqlbody {SELECT * FROM (SELECT 1) GROUP BY 1;}
    33     34   
    34     35   sqlite_malloc_fail 0
    35     36   finish_test