SQLite

Check-in [12c32f139b]
Login

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

Overview
Comment:Return SQLITE_MISUSE when passing a NULL pointer into sqlite3_bind routines. Ticket #1219. (CVS 2497)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 12c32f139bae3cb7ca520451bfc15f9f7d94833d
User & Date: drh 2005-06-06 17:54:56.000
Context
2005-06-06
21:19
Reference count Table structures so that they are not deallocated too soon. Ticket #1210. (CVS 2498) (check-in: e73d25c741 user: drh tags: trunk)
17:54
Return SQLITE_MISUSE when passing a NULL pointer into sqlite3_bind routines. Ticket #1219. (CVS 2497) (check-in: 12c32f139b user: drh tags: trunk)
17:27
Any non-zero value is considered TRUE in a WHERE clause. Ticket #1211. (CVS 2496) (check-in: 0f7af62379 user: drh tags: trunk)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/test1.c.
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
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.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.140 2005/05/27 09:41:13 danielk1977 Exp $
** $Id: test1.c,v 1.141 2005/06/06 17:54:56 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+







}
#define errorName sqlite3TestErrorName

/*
** Convert an sqlite3_stmt* into an sqlite3*.  This depends on the
** fact that the sqlite3* is the first field in the Vdbe structure.
*/
#define StmtToDb(X)   (*(sqlite3**)(X))
#define StmtToDb(X)   ((X)?*(sqlite3**)(X):0)

/*
** Check a return value to make sure it agrees with the results
** from sqlite3_errcode.
*/
int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){
  if( rc!=SQLITE_MISUSE && rc!=SQLITE_OK && sqlite3_errcode(db)!=rc ){
1601
1602
1603
1604
1605
1606
1607

1608
1609
1610
1611
1612
1613
1614
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615







+







  if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
  value = Tcl_GetString(objv[3]);
  if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;

  rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
  if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  if( rc!=SQLITE_OK ){
    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
    return TCL_ERROR;
  }

  return TCL_OK;
}

/*
Changes to src/vdbeapi.c.
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
497
498
499
500
501
502
503

504
505
506
507
508
509
510
511







-
+







**
** The error code stored in database p->db is overwritten with the return
** value in any case.
*/
static int vdbeUnbind(Vdbe *p, int i){
  Mem *pVar;
  if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
    sqlite3Error(p->db, SQLITE_MISUSE, 0);
    if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
    return SQLITE_MISUSE;
  }
  if( i<1 || i>p->nVar ){
    sqlite3Error(p->db, SQLITE_RANGE, 0);
    return SQLITE_RANGE;
  }
  i--;
Changes to test/capi3.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







# 2003 January 29
#
# 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.  The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.32 2005/05/26 16:23:34 drh Exp $
# $Id: capi3.test,v 1.33 2005/06/06 17:54:56 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.
848
849
850
851
852
853
854
855








856
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864








+
+
+
+
+
+
+
+

}
if {[llength [info commands sqlite3_sleep]]>0} {
  do_test capi3-13-5 {
    set ms [sqlite3_sleep 80]
    expr {$ms==80 || $ms==1000}
  } {1}
}

# Ticket #1219:  Make sure binding APIs can handle a NULL pointer.
#
do_test capi3-14.1 {
  set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
  lappend rc $msg
} {1 SQLITE_MISUSE}


finish_test