SQLite

Check-in [c5e45dd664]
Login

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

Overview
Comment:Tests for SQLITE_LIMIT_LENGTH enforcement in sqlite3_bind. (CVS 5369)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c5e45dd664198e5b4fc44b316bd4adbc9a6c296b
User & Date: drh 2008-07-08 15:26:50.000
Context
2008-07-08
15:59
3 more coverage tests for btree.c. (CVS 5370) (check-in: 96df0a5fa4 user: danielk1977 tags: trunk)
15:26
Tests for SQLITE_LIMIT_LENGTH enforcement in sqlite3_bind. (CVS 5369) (check-in: c5e45dd664 user: drh tags: trunk)
14:52
Improved enforcement of the SQLITE_LIMIT_LENGTH limit. (CVS 5368) (check-in: ee93150878 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/test1.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.
**
*************************************************************************
** Code for testing all sorts of SQLite interfaces.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.313 2008/07/08 03:04:59 shane Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

/*







|







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 all sorts of SQLite interfaces.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.314 2008/07/08 15:26:50 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

/*
2829
2830
2831
2832
2833
2834
2835

2836
2837
2838
2839
2840
2841
2842
  if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR;
  value = (char*)Tcl_GetByteArrayFromObj(oString, 0);
  if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR;

  rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel);
  if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  if( rc!=SQLITE_OK ){

    return TCL_ERROR;
  }

#endif /* SQLITE_OMIT_UTF16 */
  return TCL_OK;
}








>







2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
  if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR;
  value = (char*)Tcl_GetByteArrayFromObj(oString, 0);
  if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR;

  rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel);
  if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  if( rc!=SQLITE_OK ){
    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
    return TCL_ERROR;
  }

#endif /* SQLITE_OMIT_UTF16 */
  return TCL_OK;
}

Changes to test/sqllimits1.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests to verify that the limits defined in
# sqlite source file limits.h are enforced.
#
# $Id: sqllimits1.test,v 1.28 2008/04/15 02:36:34 drh Exp $

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

# Verify that the default per-connection limits are the same as
# the compile-time hard limits.
#







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests to verify that the limits defined in
# sqlite source file limits.h are enforced.
#
# $Id: sqllimits1.test,v 1.29 2008/07/08 15:26:50 drh Exp $

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

# Verify that the default per-connection limits are the same as
# the compile-time hard limits.
#
307
308
309
310
311
312
313
314
315




























316
317
318
319
320
321
322
  set ::STMT [sqlite3_prepare db "SELECT ?" -1 TAIL]
  sqlite3_bind_zeroblob $::STMT 1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
} {}
do_test sqllimits1-5.14.2 {
  sqlite3_step $::STMT 
} {SQLITE_ERROR}
do_test sqllimits1-5.14.3 {
  sqlite3_finalize $::STMT 
} {SQLITE_TOOBIG}





























do_test sqllimits1-5.15 {
  execsql {
    CREATE TABLE t4(x);
    INSERT INTO t4 VALUES(1);
    INSERT INTO t4 VALUES(2);
    INSERT INTO t4 SELECT 2+x FROM t4;







|

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







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  set ::STMT [sqlite3_prepare db "SELECT ?" -1 TAIL]
  sqlite3_bind_zeroblob $::STMT 1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
} {}
do_test sqllimits1-5.14.2 {
  sqlite3_step $::STMT 
} {SQLITE_ERROR}
do_test sqllimits1-5.14.3 {
  sqlite3_reset $::STMT 
} {SQLITE_TOOBIG}
do_test sqllimits1-5.14.4 {
  set np1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
  set ::str1 [string repeat A $np1]
  catch {sqlite3_bind_text $::STMT 1 $::str1 -1} res
  set res
} {SQLITE_TOOBIG}
do_test sqllimits1-5.14.5 {
  catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
  set res
} {SQLITE_TOOBIG}
do_test sqllimits1-5.14.6 {
  catch {sqlite3_bind_text $::STMT 1 $::str1 $np1} res
  set res
} {SQLITE_TOOBIG}
do_test sqllimits1-5.14.7 {
  catch {sqlite3_bind_text16 $::STMT 1 $::str1 $np1} res
  set res
} {SQLITE_TOOBIG}
do_test sqllimits1-5.14.8 {
  set n [expr {$np1-1}]
  catch {sqlite3_bind_text $::STMT 1 $::str1 $n} res
  set res
} {}
do_test sqllimits1-5.14.9 {
  catch {sqlite3_bind_text16 $::STMT 1 $::str1 $n} res
  set res
} {}
sqlite3_finalize $::STMT 

do_test sqllimits1-5.15 {
  execsql {
    CREATE TABLE t4(x);
    INSERT INTO t4 VALUES(1);
    INSERT INTO t4 VALUES(2);
    INSERT INTO t4 SELECT 2+x FROM t4;
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
    set expr "SELECT 1"
    for {set i 0} {$i <= $max} {incr i} {
      set expr "SELECT ($expr)"
    }
    catchsql [subst { $expr }]
  } "1 {parser stack overflow}"
  
  
  do_test sqllimits1-9.3 {
    execsql {
      PRAGMA max_page_count = 1000000;  -- 1 GB
      CREATE TABLE v0(a);
      INSERT INTO v0 VALUES(1);
    }
    db transaction {







|







650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
    set expr "SELECT 1"
    for {set i 0} {$i <= $max} {incr i} {
      set expr "SELECT ($expr)"
    }
    catchsql [subst { $expr }]
  } "1 {parser stack overflow}"
  
if 0 {  
  do_test sqllimits1-9.3 {
    execsql {
      PRAGMA max_page_count = 1000000;  -- 1 GB
      CREATE TABLE v0(a);
      INSERT INTO v0 VALUES(1);
    }
    db transaction {
644
645
646
647
648
649
650

651
652
653
654
655
656
657
  } {}
  
  do_test sqllimits1-9.4 {
    catchsql {
      SELECT a FROM v199
    }
  } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"

}

#--------------------------------------------------------------------
# Test cases sqllimits1-10.* test that the SQLITE_MAX_VDBE_OP
# limit works as expected. The limit refers to the number of opcodes
# in a single VDBE program.
#







>







672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
  } {}
  
  do_test sqllimits1-9.4 {
    catchsql {
      SELECT a FROM v199
    }
  } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
}
}

#--------------------------------------------------------------------
# Test cases sqllimits1-10.* test that the SQLITE_MAX_VDBE_OP
# limit works as expected. The limit refers to the number of opcodes
# in a single VDBE program.
#