/ Check-in [07aeca3b]
Login

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

Overview
Comment:When SQLITE_MAX_SQL_LENGTH is 0, disable the limit. Make the default 0. Once again build the sqlite3 CLI from individual source files so that it can be built on systems that lack tclsh. Tickets #2845 and #2846. (CVS 4636)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 07aeca3b9c51e538ba7939950a970f62e51bd3ea
User & Date: drh 2007-12-17 16:20:07
Context
2007-12-18
11:19
Fix for typo in main.mk: the output of target sqlite3 was testcli. (CVS 4637) check-in: 15675dc5 user: danielk1977 tags: trunk
2007-12-17
16:20
When SQLITE_MAX_SQL_LENGTH is 0, disable the limit. Make the default 0. Once again build the sqlite3 CLI from individual source files so that it can be built on systems that lack tclsh. Tickets #2845 and #2846. (CVS 4636) check-in: 07aeca3b user: drh tags: trunk
2007-12-14
17:39
Version 3.5.4 (CVS 4635) check-in: cf4a11b2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   313    313   
   314    314   libtclsqlite3.la:	tclsqlite.lo libsqlite3.la
   315    315   	$(LTLINK) -o libtclsqlite3.la tclsqlite.lo \
   316    316   		$(LIBOBJ) @TCL_STUB_LIB_SPEC@ $(LIBPTHREAD) \
   317    317                   -rpath $(libdir)/sqlite \
   318    318   		-version-info "8:6:8"
   319    319   
   320         -testcli$(TEXE):	$(TOP)/src/shell.c libsqlite3.la sqlite3.h
          320  +sqlite3$(TEXE):	$(TOP)/src/shell.c libsqlite3.la sqlite3.h
   321    321   	$(LTLINK) $(READLINE_FLAGS) $(LIBPTHREAD) \
   322    322   		-o $@ $(TOP)/src/shell.c libsqlite3.la \
   323    323   		$(LIBREADLINE) $(TLIBS)
   324    324   
   325         -sqlite3$(EXE):	$(TOP)/src/shell.c sqlite3.c sqlite3.h
   326         -	$(LTLINK) $(READLINE_FLAGS) -o $@                          \
   327         -		-DSQLITE_MAX_SQL_LENGTH=1000000000                  \
   328         -		-USQLITE_THREADSAFE -DSQLITE_THREADSAFE=0           \
   329         -		$(TOP)/src/shell.c sqlite3.c                        \
   330         -		$(LIBREADLINE) $(TLIBS) $(THREADLIB)
   331         -
   332    325   # This target creates a directory named "tsrc" and fills it with
   333    326   # copies of all of the C source code and header files needed to
   334    327   # build on the target system.  Some of the C source code and header
   335    328   # files are automatically generated.  This target takes care of
   336    329   # all that automatic generation.
   337    330   #
   338    331   target_source:	$(SRC) parse.c opcodes.c keywordhash.h $(VDBEHDR) 

Changes to main.mk.

   273    273   #
   274    274   all:	sqlite3.h libsqlite3.a sqlite3$(EXE)
   275    275   
   276    276   libsqlite3.a:	$(LIBOBJ)
   277    277   	$(AR) libsqlite3.a $(LIBOBJ)
   278    278   	$(RANLIB) libsqlite3.a
   279    279   
   280         -testcli$(EXE):	$(TOP)/src/shell.c libsqlite3.a sqlite3.h
          280  +sqlite3$(EXE):	$(TOP)/src/shell.c libsqlite3.a sqlite3.h
   281    281   	$(TCCX) $(READLINE_FLAGS) -o testcli$(EXE)                  \
   282    282   		$(TOP)/src/shell.c                                  \
   283    283   		libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB)
   284    284   
   285         -sqlite3$(EXE):	$(TOP)/src/shell.c sqlite3.c sqlite3.h
   286         -	$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE)                  \
   287         -		-DSQLITE_MAX_SQL_LENGTH=1000000000                  \
   288         -		-USQLITE_THREADSAFE -DSQLITE_THREADSAFE=0           \
   289         -		$(TOP)/src/shell.c sqlite3.c                        \
   290         -		$(LIBREADLINE) $(TLIBS) $(THREADLIB)
   291         -
   292    285   objects: $(LIBOBJ_ORIG)
   293    286   
   294    287   # This target creates a directory named "tsrc" and fills it with
   295    288   # copies of all of the C source code and header files needed to
   296    289   # build on the target system.  Some of the C source code and header
   297    290   # files are automatically generated.  This target takes care of
   298    291   # all that automatic generation.

Changes to src/sqliteLimit.h.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** 
    13     13   ** This file defines various limits of what SQLite can process.
    14     14   **
    15         -** @(#) $Id: sqliteLimit.h,v 1.5 2007/12/13 21:54:11 drh Exp $
           15  +** @(#) $Id: sqliteLimit.h,v 1.6 2007/12/17 16:20:07 drh Exp $
    16     16   */
    17     17   
    18     18   /*
    19     19   ** The maximum length of a TEXT or BLOB in bytes.   This also
    20     20   ** limits the size of a row in a table or index.
    21     21   **
    22     22   ** The hard limit is the ability of a 32-bit signed integer
................................................................................
    45     45   */
    46     46   #ifndef SQLITE_MAX_COLUMN
    47     47   # define SQLITE_MAX_COLUMN 2000
    48     48   #endif
    49     49   
    50     50   /*
    51     51   ** The maximum length of a single SQL statement in bytes.
    52         -** The hard limit is 1 million.
           52  +** A value of zero means there is no limit.
    53     53   */
    54     54   #ifndef SQLITE_MAX_SQL_LENGTH
    55         -# define SQLITE_MAX_SQL_LENGTH 1000000
           55  +# define SQLITE_MAX_SQL_LENGTH 0
    56     56   #endif
    57     57   
    58     58   /*
    59     59   ** The maximum depth of an expression tree. This is limited to 
    60     60   ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might 
    61     61   ** want to place more severe limits on the complexity of an 
    62     62   ** expression. A value of 0 (the default) means do not enforce

Changes to src/tokenize.c.

    11     11   *************************************************************************
    12     12   ** An tokenizer for SQL
    13     13   **
    14     14   ** This file contains C code that splits an SQL input string up into
    15     15   ** individual tokens and sends those tokens one-by-one over to the
    16     16   ** parser for analysis.
    17     17   **
    18         -** $Id: tokenize.c,v 1.136 2007/08/27 23:26:59 drh Exp $
           18  +** $Id: tokenize.c,v 1.137 2007/12/17 16:20:07 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include <ctype.h>
    22     22   #include <stdlib.h>
    23     23   
    24     24   /*
    25     25   ** The charMap() macro maps alphabetic characters into their
................................................................................
   414    414     pParse->zTail = pParse->zSql = zSql;
   415    415     while( !db->mallocFailed && zSql[i]!=0 ){
   416    416       assert( i>=0 );
   417    417       pParse->sLastToken.z = (u8*)&zSql[i];
   418    418       assert( pParse->sLastToken.dyn==0 );
   419    419       pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);
   420    420       i += pParse->sLastToken.n;
   421         -    if( i>SQLITE_MAX_SQL_LENGTH ){
          421  +    if( SQLITE_MAX_SQL_LENGTH>0 && i>SQLITE_MAX_SQL_LENGTH ){
   422    422         pParse->rc = SQLITE_TOOBIG;
   423    423         break;
   424    424       }
   425    425       switch( tokenType ){
   426    426         case TK_SPACE:
   427    427         case TK_COMMENT: {
   428    428           if( db->u1.isInterrupted ){

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.660 2007/12/13 21:54:11 drh Exp $
           46  +** $Id: vdbe.c,v 1.661 2007/12/17 16:20:07 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
   756    756   ** P3 points to a nul terminated UTF-8 string. This opcode is transformed 
   757    757   ** into an OP_String before it is executed for the first time.
   758    758   */
   759    759   case OP_String8: {         /* same as TK_STRING */
   760    760     assert( pOp->p3!=0 );
   761    761     pOp->opcode = OP_String;
   762    762     pOp->p1 = strlen(pOp->p3);
   763         -  assert( SQLITE_MAX_SQL_LENGTH <= SQLITE_MAX_LENGTH );
   764         -  assert( pOp->p1 <= SQLITE_MAX_LENGTH );
   765    763   
   766    764   #ifndef SQLITE_OMIT_UTF16
   767    765     if( encoding!=SQLITE_UTF8 ){
   768    766       pTos++;
   769    767       sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC);
   770    768       if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, encoding) ) goto no_mem;
   771    769       if( SQLITE_OK!=sqlite3VdbeMemDynamicify(pTos) ) goto no_mem;
................................................................................
   773    771       pTos->flags |= MEM_Static;
   774    772       if( pOp->p3type==P3_DYNAMIC ){
   775    773         sqlite3_free(pOp->p3);
   776    774       }
   777    775       pOp->p3type = P3_DYNAMIC;
   778    776       pOp->p3 = pTos->z;
   779    777       pOp->p1 = pTos->n;
   780         -    assert( pOp->p1 <= SQLITE_MAX_LENGTH ); /* Due to SQLITE_MAX_SQL_LENGTH */
          778  +    if( pOp->p1>SQLITE_MAX_LENGTH ){
          779  +      goto too_big;
          780  +    }
   781    781       break;
   782    782     }
   783    783   #endif
   784         -  /* Otherwise fall through to the next case, OP_String */
          784  +  if( pOp->p1>SQLITE_MAX_LENGTH ){
          785  +    goto too_big;
          786  +  }
          787  +  /* Fall through to the next case, OP_String */
   785    788   }
   786    789     
   787    790   /* Opcode: String P1 * P3
   788    791   **
   789    792   ** The string value P3 of length P1 (bytes) is pushed onto the stack.
   790    793   */
   791    794   case OP_String: {
   792         -  assert( pOp->p1 <= SQLITE_MAX_LENGTH ); /* Due to SQLITE_MAX_SQL_LENGTH */
   793    795     pTos++;
   794    796     assert( pOp->p3!=0 );
   795    797     pTos->flags = MEM_Str|MEM_Static|MEM_Term;
   796    798     pTos->z = pOp->p3;
   797    799     pTos->n = pOp->p1;
   798    800     pTos->enc = encoding;
   799    801     break;
................................................................................
   819    821   **
   820    822   ** The first time this instruction executes, in transforms itself into a
   821    823   ** 'Blob' opcode with a binary blob as P3.
   822    824   */
   823    825   case OP_HexBlob: {            /* same as TK_BLOB */
   824    826     pOp->opcode = OP_Blob;
   825    827     pOp->p1 = strlen(pOp->p3)/2;
   826         -  assert( SQLITE_MAX_SQL_LENGTH <= SQLITE_MAX_LENGTH );
   827         -  assert( pOp->p1 <= SQLITE_MAX_LENGTH );
          828  +  if( pOp->p1>SQLITE_MAX_LENGTH ){
          829  +    goto too_big;
          830  +  }
   828    831     if( pOp->p1 ){
   829    832       char *zBlob = sqlite3HexToBlob(db, pOp->p3);
   830    833       if( !zBlob ) goto no_mem;
   831    834       if( pOp->p3type==P3_DYNAMIC ){
   832    835         sqlite3_free(pOp->p3);
   833    836       }
   834    837       pOp->p3 = zBlob;
................................................................................
   851    854   ** by the compiler. Instead, the compiler layer specifies
   852    855   ** an OP_HexBlob opcode, with the hex string representation of
   853    856   ** the blob as P3. This opcode is transformed to an OP_Blob
   854    857   ** the first time it is executed.
   855    858   */
   856    859   case OP_Blob: {
   857    860     pTos++;
   858         -  assert( pOp->p1 <= SQLITE_MAX_LENGTH ); /* Due to SQLITE_MAX_SQL_LENGTH */
          861  +  assert( pOp->p1 <= SQLITE_MAX_LENGTH );
   859    862     sqlite3VdbeMemSetStr(pTos, pOp->p3, pOp->p1, 0, 0);
   860    863     pTos->enc = encoding;
   861    864     break;
   862    865   }
   863    866   #endif /* SQLITE_OMIT_BLOB_LITERAL */
   864    867   
   865    868   /* Opcode: Variable P1 * *

Changes to test/sqllimits1.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   # This file contains tests to verify that the limits defined in
    13     13   # sqlite source file limits.h are enforced.
    14     14   #
    15         -# $Id: sqllimits1.test,v 1.20 2007/11/28 22:36:41 drh Exp $
           15  +# $Id: sqllimits1.test,v 1.21 2007/12/17 16:20:07 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Test organization:
    21     21   #
    22     22   #     sqllimits-1.*:  SQLITE_MAX_LENGTH
................................................................................
   136    136       INSERT INTO t4 SELECT 2+x FROM t4;
   137    137     }
   138    138     catchsql {
   139    139       SELECT group_concat(hex(randomblob(20000))) FROM t4;
   140    140     }
   141    141   } {1 {string or blob too big}}
   142    142   db eval {DROP TABLE t4}
          143  +
          144  +set ::SQLITE_MAX_SQL_LENGTH 0
          145  +set strvalue [string repeat A $::SQLITE_MAX_LENGTH]
          146  +do_test sqllimits-1.16 {
          147  +  catchsql "SELECT '$strvalue'"
          148  +} [list 0 $strvalue]
          149  +do_test sqllimits-1.17 {
          150  +  catchsql "SELECT 'A$strvalue'"
          151  +} [list 1 {string or blob too big}]
          152  +set blobvalue [string repeat 41 $::SQLITE_MAX_LENGTH]
          153  +do_test sqllimits-1.18 {
          154  +  catchsql "SELECT x'$blobvalue'"
          155  +} [list 0 $strvalue]
          156  +do_test sqllimits-1.19 {
          157  +  catchsql "SELECT '41$blobvalue'"
          158  +} [list 1 {string or blob too big}]
          159  +unset strvalue
          160  +unset blobvalue
   143    161   
   144    162   #--------------------------------------------------------------------
   145    163   # Test cases sqllimits-2.* test that the SQLITE_MAX_SQL_LENGTH limit
   146    164   # is enforced.
   147    165   #
   148    166   do_test sqllimits-2.1 {
   149         -  set    sql "SELECT 1 WHERE 1==1"
   150         -  set N [expr {$::SQLITE_MAX_SQL_LENGTH / [string length " AND 1==1"]}]
   151         -  append sql [string repeat " AND 1==1" $N]
          167  +  set ::SQLITE_MAX_SQL_LENGTH 50000
          168  +  set sql "SELECT 1 WHERE 1==1"
          169  +  set tail " /* A comment to take up space in order to make the string\
          170  +                longer without increasing the expression depth */\
          171  +                AND   1  ==  1"
          172  +  set N [expr {($::SQLITE_MAX_SQL_LENGTH / [string length $tail])+1}]
          173  +  append sql [string repeat $tail $N]
   152    174     catchsql $sql
   153    175   } {1 {String or BLOB exceeded size limit}}
          176  +do_test sqllimits-2.2 {
          177  +  set ::SQLITE_MAX_SQL_LENGTH 0
          178  +  catchsql $sql
          179  +} {0 1}
   154    180   
   155    181   #--------------------------------------------------------------------
   156    182   # Test cases sqllimits-3.* test that the limit set using the
   157    183   # max_page_count pragma.
   158    184   #
   159    185   do_test sqllimits-3.1 {
   160    186     execsql {