Add a test case to trigger an assertion fault when running
sqlite3_prepare16() with a predefined string size. (CVS 3337) FossilOrigin-Name: 93878e6ebf703be022f83fd670c1aaaf7d4f1266
This commit is contained in:
parent
15ca1df1bf
commit
aa0fe8070d
11
manifest
11
manifest
@ -1,5 +1,5 @@
|
||||
C More\swork\stoward\sgetting\ssqlite3_interrupt()\sto\swork\sfrom\sseparate\nthreads.\s\sTicket\s#1897.\s(CVS\s3336)
|
||||
D 2006-07-26T13:43:31
|
||||
C Add\sa\stest\scase\sto\strigger\san\sassertion\sfault\swhen\srunning\nsqlite3_prepare16()\swith\sa\spredefined\sstring\ssize.\s(CVS\s3337)
|
||||
D 2006-07-26T14:49:19
|
||||
F Makefile.in 9c2a76055c305868cc5f5b73e29a252ff3632c0a
|
||||
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
|
||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||
@ -207,6 +207,7 @@ F test/malloc3.test fd4186bee73c2a2638f4e2a05a684c06836f725b
|
||||
F test/malloc4.test 59cd02f71b363302a04c4e77b97c0a1572eaa210
|
||||
F test/malloc5.test 7425272e263325fda7d32cb55706e52b5c09e7e0
|
||||
F test/malloc6.test 025ae0b78542e0ddd000d23f79d93e9be9ba0f15
|
||||
F test/malloc7.test 436b90dbe4a22a2f5309124f3b13ff33082e162d
|
||||
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
|
||||
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
|
||||
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
|
||||
@ -376,7 +377,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||
P 35fd67d7a0c55797eb460e3bd02c96afe619f026
|
||||
R 81058f7cc0073e22a60fae6f780adbf1
|
||||
P e431131d47481f9fc64c498e8934b10a96b0a931
|
||||
R 7e8761d6a912e35c00881f2d7e6d80bf
|
||||
U drh
|
||||
Z 506916b1bf3ff2edf2b1a6a42bca76f1
|
||||
Z 2f225d06d095b7c64a3eddb40e300558
|
||||
|
@ -1 +1 @@
|
||||
e431131d47481f9fc64c498e8934b10a96b0a931
|
||||
93878e6ebf703be022f83fd670c1aaaf7d4f1266
|
149
test/malloc7.test
Normal file
149
test/malloc7.test
Normal file
@ -0,0 +1,149 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# 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 attempts to check the library in an out-of-memory situation.
|
||||
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
|
||||
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail. This
|
||||
# special feature is used to see what happens in the library if a malloc
|
||||
# were to really fail due to an out-of-memory situation.
|
||||
#
|
||||
# $Id: malloc7.test,v 1.1 2006/07/26 14:49:19 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Usage: do_malloc_test <test number> <options...>
|
||||
#
|
||||
# The first argument, <test number>, is an integer used to name the
|
||||
# tests executed by this proc. Options are as follows:
|
||||
#
|
||||
# -tclprep TCL script to run to prepare test.
|
||||
# -sqlprep SQL script to run to prepare test.
|
||||
# -tclbody TCL script to run with malloc failure simulation.
|
||||
# -sqlbody TCL script to run with malloc failure simulation.
|
||||
# -cleanup TCL script to run after the test.
|
||||
#
|
||||
# This command runs a series of tests to verify SQLite's ability
|
||||
# to handle an out-of-memory condition gracefully. It is assumed
|
||||
# that if this condition occurs a malloc() call will return a
|
||||
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||
# the "BUGS" section of malloc(3).
|
||||
#
|
||||
# Each iteration of a loop, the TCL commands in any argument passed
|
||||
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||
# passed to the -sqlbody switch are executed. Each iteration the
|
||||
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||
# each time the loop runs starting from 1. When all commands execute
|
||||
# successfully, the loop ends.
|
||||
#
|
||||
proc do_malloc_test {tn args} {
|
||||
array unset ::mallocopts
|
||||
array set ::mallocopts $args
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go && $::n < 50000} {incr ::n} {
|
||||
do_test malloc7-$tn.$::n {
|
||||
|
||||
# Remove all traces of database files test.db and test2.db from the files
|
||||
# system. Then open (empty database) "test.db" with the handle [db].
|
||||
#
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
catch {sqlite3 db test.db}
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
|
||||
# Execute any -tclprep and -sqlprep scripts.
|
||||
#
|
||||
if {[info exists ::mallocopts(-tclprep)]} {
|
||||
eval $::mallocopts(-tclprep)
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||
execsql $::mallocopts(-sqlprep)
|
||||
}
|
||||
|
||||
# Now set the ${::n}th malloc() to fail and execute the -tclbody and
|
||||
# -sqlbody scripts.
|
||||
#
|
||||
sqlite_malloc_fail $::n
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
set v [catch $::mallocbody msg]
|
||||
|
||||
# If the test fails (if $v!=0) and the database connection actually
|
||||
# exists, make sure the failure code is SQLITE_NOMEM.
|
||||
if {$v && [info command db]=="db" && [info exists ::mallocopts(-sqlbody)]
|
||||
&& [db errorcode]!=7} {
|
||||
set v 999
|
||||
}
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
if {$v} {
|
||||
puts "\nError message returned: $msg"
|
||||
} else {
|
||||
set v {1 1}
|
||||
}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
catch [list uplevel #0 $::mallocopts(-cleanup)] msg
|
||||
}
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
|
||||
db eval {
|
||||
CREATE TABLE t1(a,b,c,d);
|
||||
CREATE INDEX i1 ON t1(b,c);
|
||||
}
|
||||
|
||||
do_malloc_test 1 -tclbody {
|
||||
set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
|
||||
append sql16 "\00\00"
|
||||
set nbyte [string length $sql16]
|
||||
set ::STMT [sqlite3_prepare16 $::DB $sql16 $nbyte DUMMY]
|
||||
sqlite3_finalize $::STMT
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Ensure that no file descriptors were leaked.
|
||||
do_test malloc-99.X {
|
||||
catch {db close}
|
||||
set sqlite_open_file_count
|
||||
} {0}
|
||||
|
||||
puts open-file-count=$sqlite_open_file_count
|
||||
sqlite_malloc_fail 0
|
||||
finish_test
|
Loading…
x
Reference in New Issue
Block a user