/ Check-in [783f19be]
Login

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

Overview
Comment:Do not segfault even if sqlite is misused by requesting query results after the query has been reset. ticket #2426. (CVS 4090)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 783f19be387561fbca3ac7e223bdb7dedb5450c8
User & Date: drh 2007-06-19 10:58:24
Context
2007-06-19
15:23
Change the name of the "limits.h" source file to "sqliteLimit.h". Ticket #2428. (CVS 4091) check-in: 64bcc41f user: drh tags: trunk
10:58
Do not segfault even if sqlite is misused by requesting query results after the query has been reset. ticket #2426. (CVS 4090) check-in: 783f19be user: drh tags: trunk
10:50
Cast the 2nd parameter of ftruncate to off_t to work around bugs in some unix implementations. Ticket #2425. (CVS 4089) check-in: 0b20a696 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbeapi.c.

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
** it is, return a pointer to the Mem for the value of that column.
** If iCol is not valid, return a pointer to a Mem which has a value
** of NULL.
*/
static Mem *columnMem(sqlite3_stmt *pStmt, int i){
  Vdbe *pVm = (Vdbe *)pStmt;
  int vals = sqlite3_data_count(pStmt);
  if( i>=vals || i<0 ){
    static const Mem nullMem = {{0}, 0.0, "", 0, MEM_Null, SQLITE_NULL };
    sqlite3Error(pVm->db, SQLITE_RANGE, 0);
    return (Mem*)&nullMem;
  }
  return &pVm->pTos[(1-vals)+i];
}








|







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
** it is, return a pointer to the Mem for the value of that column.
** If iCol is not valid, return a pointer to a Mem which has a value
** of NULL.
*/
static Mem *columnMem(sqlite3_stmt *pStmt, int i){
  Vdbe *pVm = (Vdbe *)pStmt;
  int vals = sqlite3_data_count(pStmt);
  if( pVm==0 || pVm->resOnStack==0 || i>=pVm->nResColumn || i<0 ){
    static const Mem nullMem = {{0}, 0.0, "", 0, MEM_Null, SQLITE_NULL };
    sqlite3Error(pVm->db, SQLITE_RANGE, 0);
    return (Mem*)&nullMem;
  }
  return &pVm->pTos[(1-vals)+i];
}

Changes to test/capi3.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
....
1040
1041
1042
1043
1044
1045
1046


1047












1048
1049
#    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.  The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.48 2007/03/30 20:46:13 drh Exp $
#

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

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
} {1}
do_test capi3-16.4 {
  set STMT [sqlite3_prepare $DB {;} -1 TAIL]
  sqlite3_finalize $STMT
  expr {$STMT==""}
} {1}

















finish_test







|







 







>
>
|
>
>
>
>
>
>
>
>
>
>
>
>


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
....
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
#    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.  The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.49 2007/06/19 10:58:24 drh Exp $
#

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

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
} {1}
do_test capi3-16.4 {
  set STMT [sqlite3_prepare $DB {;} -1 TAIL]
  sqlite3_finalize $STMT
  expr {$STMT==""}
} {1}

# Ticket #2426:  Misuse of sqlite3_column_* by calling it after
# a sqlite3_reset should be harmless.
#
do_test capi3-17.1 {
  set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
  sqlite3_step $STMT
  sqlite3_column_int $STMT 0
} {1}
do_test capi3-17.2 {
  sqlite3_reset $STMT
  sqlite3_column_int $STMT 0
} {0}
do_test capi3-17.3 {
  sqlite3_finalize $STMT
} {SQLITE_OK}

finish_test