Prevent databases from being DETACHed while they are in use. Fix for #1873. (CVS 3312)

FossilOrigin-Name: 70a48b250bab99c5d9b4ad17c471663b8628e8d2
This commit is contained in:
danielk1977 2006-06-27 16:34:56 +00:00
parent c2e87a3e85
commit 2372c2b165
6 changed files with 93 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C The\sability\sto\sload\sextensions\sis\sturned\soff\sby\sdefault.\s\sIt\smust\sbe\nenabled\sby\scalling\ssqlite3_enable_load_extension()\sbefore\sit\swill\swork.\nThis\sprevents\ssecurity\sproblems\sin\slegacy\sapplications.\s\sTicket\s#1863.\s(CVS\s3311)
D 2006-06-27T15:16:15
C Prevent\sdatabases\sfrom\sbeing\sDETACHed\swhile\sthey\sare\sin\suse.\sFix\sfor\s#1873.\s(CVS\s3312)
D 2006-06-27T16:34:57
F Makefile.in f839b470345d3cb4b0644068474623fe2464b5d3
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -32,10 +32,10 @@ F sqlite3.def f756049b1bf3e8442baf6862db393ca423225262
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
F src/alter.c eba661e77bfd00282fbfa316cdb6aef04856fedc
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
F src/attach.c 27a31d3b89d7ebb5b358847607b1ec795384123c
F src/attach.c b11eb4d5d3fb99a10a626956bccc7215f6b68b16
F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
F src/btree.c ed343b3dbcbc7da9ac481ef2b98c4239fe6d9629
F src/btree.h 40055cfc09defd1146bc5b922399c035f969e56d
F src/btree.c fc077741b35efd2015b0f56e62d00370bed1fcc8
F src/btree.h 061c50e37de7f50b58528e352d400cf33ead7418
F src/build.c ef710ff6b3a91d4c1dd4c7009a8800ff38660613
F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429
F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
@ -271,6 +271,7 @@ F test/tkt1537.test e3a14332de9770be8ff14bd15c19a49cbec10808
F test/tkt1567.test 18023cc3626a365f0118e17b66decedec93b1a6f
F test/tkt1644.test 80b6a2bb17885f3cf1cb886d97cdad13232bb869
F test/tkt1667.test ef52c857940755ea5eab24d68f808826e7dcdc94
F test/tkt1873.test 7159a1c1bf627bbb03f11362e4ad4de11d6ff316
F test/trace.test 75ffc1b992c780d054748a656e3e7fd674f18567
F test/trans.test 06bff0246886858793fca3748721936e2f65e3df
F test/trigger1.test e8c717e959c2f98c8181cd9466e140fa7aac781f
@ -374,7 +375,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 783369e870df9d189fc75c98fa574fe4fc9843d0
R 03b010c340d22a562ee989d0414f81c5
U drh
Z b75df8d7be6621720643222d3b606d63
P 4692319ccf28b0ebe64d5c5d189f444034fe0cb2
R 00197d0cb5b5b0794b65c7727c5ea79d
U danielk1977
Z 1504eda4a9a7a809d58a186051ca9568

View File

@ -1 +1 @@
4692319ccf28b0ebe64d5c5d189f444034fe0cb2
70a48b250bab99c5d9b4ad17c471663b8628e8d2

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.52 2006/05/25 11:52:38 drh Exp $
** $Id: attach.c,v 1.53 2006/06/27 16:34:57 danielk1977 Exp $
*/
#include "sqliteInt.h"
@ -247,6 +247,10 @@ static void detachFunc(
strcpy(zErr, "cannot DETACH database within transaction");
goto detach_error;
}
if( sqlite3BtreeIsInReadTrans(pDb->pBt) ){
sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
goto detach_error;
}
sqlite3BtreeClose(pDb->pBt);
pDb->pBt = 0;

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.324 2006/04/04 01:54:55 drh Exp $
** $Id: btree.c,v 1.325 2006/06/27 16:34:57 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@ -6558,6 +6558,13 @@ int sqlite3BtreeIsInStmt(Btree *p){
return (p->pBt && p->pBt->inStmt);
}
/*
** Return non-zero if a read (or write) transaction is active.
*/
int sqlite3BtreeIsInReadTrans(Btree *p){
return (p && (p->inTrans!=TRANS_NONE));
}
/*
** This call is a no-op if no write-transaction is currently active on pBt.
**

View File

@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.70 2006/02/11 01:25:51 drh Exp $
** @(#) $Id: btree.h,v 1.71 2006/06/27 16:34:57 danielk1977 Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
@ -75,6 +75,7 @@ int sqlite3BtreeRollbackStmt(Btree*);
int sqlite3BtreeCreateTable(Btree*, int*, int flags);
int sqlite3BtreeIsInTrans(Btree*);
int sqlite3BtreeIsInStmt(Btree*);
int sqlite3BtreeIsInReadTrans(Btree*);
int sqlite3BtreeSync(Btree*, const char *zMaster);
void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
int sqlite3BtreeSchemaLocked(Btree *);

67
test/tkt1873.test Normal file
View File

@ -0,0 +1,67 @@
# 2006 June 27
#
# 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.
#
# This file implements tests to verify that ticket #1873 has been
# fixed.
#
#
# $Id: tkt1873.test,v 1.1 2006/06/27 16:34:58 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
file delete -force test2.db test2.db-journal
do_test tkt1873-1.1 {
execsql {
CREATE TABLE t1(x, y);
ATTACH 'test2.db' AS aux;
CREATE TABLE aux.t2(x, y);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t2 VALUES(5, 6);
INSERT INTO t2 VALUES(7, 8);
}
} {}
do_test tkt1873-1.2 {
set rc [catch {
db eval {SELECT * FROM t2 LIMIT 1} {
db eval {DETACH aux}
}
} msg]
list $rc $msg
} {1 {database aux is locked}}
do_test tkt1873-1.3 {
set rc [catch {
db eval {SELECT * FROM t1 LIMIT 1} {
db eval {DETACH aux}
}
} msg]
list $rc $msg
} {0 {}}
do_test tkt1873-1.4 {
catchsql {
select * from t2;
}
} {1 {no such table: t2}}
do_test tkt1873-1.5 {
catchsql {
ATTACH 'test2.db' AS aux;
select * from t2;
}
} {0 {5 6 7 8}}
finish_test