SQLite

Check-in [b055bfc4e5]
Login

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

Overview
Comment:If sqlite3_column_value() is called to obtain a value with the MEM_Static flag set, clear it and set the MEM_Ephem flag before returning. Otherwise, if the value is passed to sqlite3_bind_value() or sqlite3_result_value(), sqlite may attempt to use the buffer after the statement has been finalized. This is not always valid, as MEM_Static only guarantees that a MEM.z buffer will be valid for the lifetime of the owner statement, not that it is actually a static buffer. (CVS 5812)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b055bfc4e5268d8a66d6a4f5e8aec1285fe4b8e7
User & Date: danielk1977 2008-10-13 10:37:50.000
Context
2008-10-13
10:56
Use one less temporary table in genfkey.c. The retired table was being used to workaround the bug fixed by (5812). (CVS 5813) (check-in: 73efca985a user: danielk1977 tags: trunk)
10:37
If sqlite3_column_value() is called to obtain a value with the MEM_Static flag set, clear it and set the MEM_Ephem flag before returning. Otherwise, if the value is passed to sqlite3_bind_value() or sqlite3_result_value(), sqlite may attempt to use the buffer after the statement has been finalized. This is not always valid, as MEM_Static only guarantees that a MEM.z buffer will be valid for the lifetime of the owner statement, not that it is actually a static buffer. (CVS 5812) (check-in: b055bfc4e5 user: danielk1977 tags: trunk)
2008-10-12
02:27
Check for failures in winTruncate. Ticket #3415. (CVS 5811) (check-in: 500c50561f user: shane tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbeapi.c.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code use to implement APIs that are part of the
** VDBE.
**
** $Id: vdbeapi.c,v 1.146 2008/10/12 00:27:54 shane Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"

#if 0 && defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
/*
** The following structure contains pointers to the end points of a







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code use to implement APIs that are part of the
** VDBE.
**
** $Id: vdbeapi.c,v 1.147 2008/10/13 10:37:50 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"

#if 0 && defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
/*
** The following structure contains pointers to the end points of a
833
834
835
836
837
838
839
840




841
842
843
844
845
846
847
848
849
}
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
  const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
  columnMallocFailure(pStmt);
  return val;
}
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
  sqlite3_value *pOut = columnMem(pStmt, i);




  columnMallocFailure(pStmt);
  return pOut;
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
  const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
  columnMallocFailure(pStmt);
  return val;
}







|
>
>
>
>

|







833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
}
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
  const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
  columnMallocFailure(pStmt);
  return val;
}
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
  Mem *pOut = columnMem(pStmt, i);
  if( pOut->flags&MEM_Static ){
    pOut->flags &= ~MEM_Static;
    pOut->flags |= MEM_Ephem;
  }
  columnMallocFailure(pStmt);
  return (sqlite3_value *)pOut;
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
  const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
  columnMallocFailure(pStmt);
  return val;
}
Changes to test/eval.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file experiments with recursion using the "test_eval()" SQL function
# in order to make sure that SQLite is reentrant.
#
# $Id: eval.test,v 1.1 2008/07/11 21:02:54 drh Exp $

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

# Create a table to work with.
#
do_test eval-1.1 {







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file experiments with recursion using the "test_eval()" SQL function
# in order to make sure that SQLite is reentrant.
#
# $Id: eval.test,v 1.2 2008/10/13 10:37:50 danielk1977 Exp $

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

# Create a table to work with.
#
do_test eval-1.1 {
63
64
65
66
67
68
69
70




71
#
do_test eval-3.1 {
  execsql {
    INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
    SELECT x, test_eval('UPDATE t2 SET y=y+100 WHERE x='||x), y FROM t2;
  }
} {1 {} 102 2 {} 103 3 {} 104 4 {} 105}





finish_test








>
>
>
>

63
64
65
66
67
68
69
70
71
72
73
74
75
#
do_test eval-3.1 {
  execsql {
    INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
    SELECT x, test_eval('UPDATE t2 SET y=y+100 WHERE x='||x), y FROM t2;
  }
} {1 {} 102 2 {} 103 3 {} 104 4 {} 105}

do_test eval-4.1 {
  execsql { SELECT test_eval('SELECT "abcdefghij"') }
} {abcdefghij}

finish_test
Changes to test/vtab2.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2006 June 10
#
# 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 SQLite library.
#
# $Id: vtab2.test,v 1.8 2008/01/31 15:53:46 drh Exp $

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

ifcapable !vtab||!schema_pragmas {
  finish_test
  return












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2006 June 10
#
# 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 SQLite library.
#
# $Id: vtab2.test,v 1.9 2008/10/13 10:37:50 danielk1977 Exp $

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

ifcapable !vtab||!schema_pragmas {
  finish_test
  return
100
101
102
103
104
105
106
107




























108
do_test vtab2-3.2 {
  execsql {
    SELECT *, b.rowid
      FROM schema a LEFT JOIN schema b ON a.dflt_value=b.dflt_value
     WHERE a.rowid=1
  }
} {main schema 0 database {} 0 {} 0 {} {} {} {} {} {} {} {} {}}





























finish_test








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

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
do_test vtab2-3.2 {
  execsql {
    SELECT *, b.rowid
      FROM schema a LEFT JOIN schema b ON a.dflt_value=b.dflt_value
     WHERE a.rowid=1
  }
} {main schema 0 database {} 0 {} 0 {} {} {} {} {} {} {} {} {}}

do_test vtab2-4.1 {
  execsql {
    BEGIN TRANSACTION;
    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c));
    CREATE TABLE fkey(
      to_tbl,
      to_col
    );
    INSERT INTO "fkey" VALUES('t1',NULL);
    COMMIT;
  }
} {}
do_test vtab2-4.2 {
  execsql { CREATE VIRTUAL TABLE v_col USING schema }
} {}
do_test vtab2-4.3 {
  execsql { SELECT name FROM v_col WHERE tablename = 't1' AND pk }
} {a}
do_test vtab2-4.4 {
  execsql {
    UPDATE fkey 
    SET to_col = (SELECT name FROM v_col WHERE tablename = 't1' AND pk);
  }
} {}
do_test vtab2-4.5 {
  execsql { SELECT * FROM fkey }
} {t1 a}

finish_test