SQLite

Check-in [c6635a71db]
Login

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

Overview
Comment:Fix a segfault that may follow a malloc failure during compilation of an INSTEAD OF trigger. (CVS 4749)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c6635a71dbb2a06d56a0cfce7f0383325e12dc01
User & Date: danielk1977 2008-01-24 14:27:44.000
Context
2008-01-25
15:04
Error messages says "no such view" instead of "no such table" when trying to DROP a VIEW that does not exist. (CVS 4750) (check-in: 50815a82e0 user: drh tags: trunk)
2008-01-24
14:27
Fix a segfault that may follow a malloc failure during compilation of an INSTEAD OF trigger. (CVS 4749) (check-in: c6635a71db user: danielk1977 tags: trunk)
2008-01-23
17:13
Fix another segfault that can occur following a malloc failure in the SQL compiler. (CVS 4748) (check-in: 9d98a3f0dd user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/select.c.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.409 2008/01/23 17:13:41 danielk1977 Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.410 2008/01/24 14:27:44 danielk1977 Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
**
** If possible, the SELECT statement is modified so that NULL values
** are stored in the temporary table for all columns for which the 
** corresponding bit in argument mask is not set. If mask takes the
** special value 0xffffffff, then all columns are populated.
*/
void sqlite3SelectMask(Parse *pParse, Select *p, u32 mask){
  if( !p->pPrior && !p->isDistinct && mask!=0xffffffff ){
    ExprList *pEList;
    int i;
    sqlite3SelectResolve(pParse, p, 0);
    pEList = p->pEList;
    for(i=0; i<pEList->nExpr && i<32; i++){
      if( !(mask&((u32)1<<i)) ){
        sqlite3ExprDelete(pEList->a[i].pExpr);
        pEList->a[i].pExpr = sqlite3Expr(pParse->db, TK_NULL, 0, 0, 0);
      }
    }
  }
}







|




|







2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
**
** If possible, the SELECT statement is modified so that NULL values
** are stored in the temporary table for all columns for which the 
** corresponding bit in argument mask is not set. If mask takes the
** special value 0xffffffff, then all columns are populated.
*/
void sqlite3SelectMask(Parse *pParse, Select *p, u32 mask){
  if( p && !p->pPrior && !p->isDistinct && mask!=0xffffffff ){
    ExprList *pEList;
    int i;
    sqlite3SelectResolve(pParse, p, 0);
    pEList = p->pEList;
    for(i=0; pEList && i<pEList->nExpr && i<32; i++){
      if( !(mask&((u32)1<<i)) ){
        sqlite3ExprDelete(pEList->a[i].pExpr);
        pEList->a[i].pExpr = sqlite3Expr(pParse->db, TK_NULL, 0, 0, 0);
      }
    }
  }
}
Changes to test/malloc.test.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# which causes the N-th malloc to fail.  This special feature is used
# to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.57 2008/01/23 17:13:41 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# which causes the N-th malloc to fail.  This special feature is used
# to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.58 2008/01/24 14:27:44 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {
570
571
572
573
574
575
576
577
578
579
580
581
582














583
584
585
586
587
588
589
590
591
  } -cleanup {
    set e [db eval {PRAGMA integrity_check}]
    if {$e ne "ok"} {error $e}
  }
}

ifcapable compound {
  do_malloc_test 24 -start 19 -sqlprep {
    CREATE TABLE t1(a, b, c)
  } -sqlbody {
    SELECT 1 FROM t1 UNION SELECT 2 FROM t1 ORDER BY 1
  }
}















# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
  catch {db close}
  set sqlite_open_file_count
} {0}

puts open-file-count=$sqlite_open_file_count
finish_test







|





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









570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
  } -cleanup {
    set e [db eval {PRAGMA integrity_check}]
    if {$e ne "ok"} {error $e}
  }
}

ifcapable compound {
  do_malloc_test 24 -sqlprep {
    CREATE TABLE t1(a, b, c)
  } -sqlbody {
    SELECT 1 FROM t1 UNION SELECT 2 FROM t1 ORDER BY 1
  }
}

ifcapable view&&trigger {
  do_malloc_test 25 -sqlprep {
    CREATE TABLE t1(a, b, c);
    CREATE VIEW v1 AS SELECT * FROM t1;
    CREATE TRIGGER v1t1 INSTEAD OF DELETE ON v1 BEGIN SELECT 1; END;
    CREATE TRIGGER v1t2 INSTEAD OF INSERT ON v1 BEGIN SELECT 1; END;
    CREATE TRIGGER v1t3 INSTEAD OF UPDATE ON v1 BEGIN SELECT 1; END;
  } -sqlbody {
    DELETE FROM v1 WHERE a = 1;
    INSERT INTO v1 VALUES(1, 2, 3);
    UPDATE v1 SET a = 1 WHERE b = 2;
  }
}

# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
  catch {db close}
  set sqlite_open_file_count
} {0}

puts open-file-count=$sqlite_open_file_count
finish_test