/ Check-in [12c32f13]
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 | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 12c32f139bae3cb7ca520451bfc15f9f7d94833d
User & Date: drh 2005-06-06 17:54:56
Context
2005-06-06
21:19
Reference count Table structures so that they are not deallocated too soon. Ticket #1210. (CVS 2498) check-in: e73d25c7 user: drh tags: trunk
17:54
Return SQLITE_MISUSE when passing a NULL pointer into sqlite3_bind routines. Ticket #1219. (CVS 2497) check-in: 12c32f13 user: drh tags: trunk
17:27
Any non-zero value is considered TRUE in a WHERE clause. Ticket #1211. (CVS 2496) check-in: 0f7af623 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.140 2005/05/27 09:41:13 danielk1977 Exp $
           16  +** $Id: test1.c,v 1.141 2005/06/06 17:54:56 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
    59     59   }
    60     60   #define errorName sqlite3TestErrorName
    61     61   
    62     62   /*
    63     63   ** Convert an sqlite3_stmt* into an sqlite3*.  This depends on the
    64     64   ** fact that the sqlite3* is the first field in the Vdbe structure.
    65     65   */
    66         -#define StmtToDb(X)   (*(sqlite3**)(X))
           66  +#define StmtToDb(X)   ((X)?*(sqlite3**)(X):0)
    67     67   
    68     68   /*
    69     69   ** Check a return value to make sure it agrees with the results
    70     70   ** from sqlite3_errcode.
    71     71   */
    72     72   int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){
    73     73     if( rc!=SQLITE_MISUSE && rc!=SQLITE_OK && sqlite3_errcode(db)!=rc ){
................................................................................
  1601   1601     if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
  1602   1602     value = Tcl_GetString(objv[3]);
  1603   1603     if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
  1604   1604   
  1605   1605     rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
  1606   1606     if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  1607   1607     if( rc!=SQLITE_OK ){
         1608  +    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
  1608   1609       return TCL_ERROR;
  1609   1610     }
  1610   1611   
  1611   1612     return TCL_OK;
  1612   1613   }
  1613   1614   
  1614   1615   /*

Changes to src/vdbeapi.c.

   497    497   **
   498    498   ** The error code stored in database p->db is overwritten with the return
   499    499   ** value in any case.
   500    500   */
   501    501   static int vdbeUnbind(Vdbe *p, int i){
   502    502     Mem *pVar;
   503    503     if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
   504         -    sqlite3Error(p->db, SQLITE_MISUSE, 0);
          504  +    if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
   505    505       return SQLITE_MISUSE;
   506    506     }
   507    507     if( i<1 || i>p->nVar ){
   508    508       sqlite3Error(p->db, SQLITE_RANGE, 0);
   509    509       return SQLITE_RANGE;
   510    510     }
   511    511     i--;

Changes to test/capi3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi3.test,v 1.32 2005/05/26 16:23:34 drh Exp $
           14  +# $Id: capi3.test,v 1.33 2005/06/06 17:54:56 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    21     21   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
   848    848   }
   849    849   if {[llength [info commands sqlite3_sleep]]>0} {
   850    850     do_test capi3-13-5 {
   851    851       set ms [sqlite3_sleep 80]
   852    852       expr {$ms==80 || $ms==1000}
   853    853     } {1}
   854    854   }
          855  +
          856  +# Ticket #1219:  Make sure binding APIs can handle a NULL pointer.
          857  +#
          858  +do_test capi3-14.1 {
          859  +  set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
          860  +  lappend rc $msg
          861  +} {1 SQLITE_MISUSE}
          862  +
   855    863   
   856    864   finish_test