mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-14 00:22:38 +03:00
Take care not to leave a zombie attached database if the attachment fails
due to an encoding mismatch. Update attach logic to always use dynamically allocated error message strings. (CVS 6573) FossilOrigin-Name: a6cb4002ada311b56fa2b7430b98b9a0fa698a01
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
||||
C Remove\salways-true\stests\sfrom\sattach.c.\s\sIn\sbtree.c,\salways\stest\sthe\sreturn\nfrom\ssqlite3PagerSetPagesize()\ssince\sit\smight\sreturn\sSQLITE_NOMEM.\s(CVS\s6572)
|
||||
D 2009-04-30T01:22:41
|
||||
C Take\scare\snot\sto\sleave\sa\szombie\sattached\sdatabase\sif\sthe\sattachment\sfails\ndue\sto\san\sencoding\smismatch.\s\sUpdate\sattach\slogic\sto\salways\suse\sdynamically\nallocated\serror\smessage\sstrings.\s(CVS\s6573)
|
||||
D 2009-04-30T05:19:04
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@@ -101,7 +101,7 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
||||
F src/alter.c 8ab5824bde0a03dae5829f61557ab7c72757000a
|
||||
F src/analyze.c e239496cfb5394ac8867f1c112905ddab8d01cd9
|
||||
F src/attach.c b3bc7d3c63426abebc28866a62ed317d9a207895
|
||||
F src/attach.c 38e6ad955ac54be32d2daa55fffdfbdc7cd01ace
|
||||
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
|
||||
F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d
|
||||
F src/bitvec.c ef370407e03440b0852d05024fb016b14a471d3d
|
||||
@@ -725,7 +725,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P 71756dc870910665ef5fdbc7343bc3eedbe3ce65
|
||||
R deffbd686d1897bfec739f5ed6ad0e41
|
||||
P 8bf60b24ffcf6ac15f41eaa7f976b810e0c66734
|
||||
R 32e5b87554b74f04442dc5abc482ed4a
|
||||
U drh
|
||||
Z b2a0488e881b8258a5c5a932a53fd373
|
||||
Z f244ab0788ad7a9d214fdf73c2314ea5
|
||||
|
||||
@@ -1 +1 @@
|
||||
8bf60b24ffcf6ac15f41eaa7f976b810e0c66734
|
||||
a6cb4002ada311b56fa2b7430b98b9a0fa698a01
|
||||
29
src/attach.c
29
src/attach.c
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.85 2009/04/30 01:22:41 drh Exp $
|
||||
** $Id: attach.c,v 1.86 2009/04/30 05:19:04 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -74,7 +74,6 @@ static void attachFunc(
|
||||
const char *zFile;
|
||||
Db *aNew;
|
||||
char *zErrDyn = 0;
|
||||
char zErr[128];
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
@@ -90,23 +89,20 @@ static void attachFunc(
|
||||
** * Specified database name already being used.
|
||||
*/
|
||||
if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
|
||||
sqlite3_snprintf(
|
||||
sizeof(zErr), zErr, "too many attached databases - max %d",
|
||||
zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
|
||||
db->aLimit[SQLITE_LIMIT_ATTACHED]
|
||||
);
|
||||
goto attach_error;
|
||||
}
|
||||
if( !db->autoCommit ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr,
|
||||
"cannot ATTACH database within transaction");
|
||||
zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
|
||||
goto attach_error;
|
||||
}
|
||||
for(i=0; i<db->nDb; i++){
|
||||
char *z = db->aDb[i].zName;
|
||||
assert( z && zName );
|
||||
if( sqlite3StrICmp(z, zName)==0 ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr,
|
||||
"database %s is already in use", zName);
|
||||
zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
|
||||
goto attach_error;
|
||||
}
|
||||
}
|
||||
@@ -139,9 +135,9 @@ static void attachFunc(
|
||||
if( !aNew->pSchema ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
|
||||
sqlite3_snprintf(sizeof(zErr), zErr,
|
||||
zErrDyn = sqlite3MPrintf(db,
|
||||
"attached databases must use the same text encoding as main database");
|
||||
goto attach_error;
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
pPager = sqlite3BtreePager(aNew->pBt);
|
||||
sqlite3PagerLockingMode(pPager, db->dfltLockMode);
|
||||
@@ -204,9 +200,9 @@ static void attachFunc(
|
||||
db->nDb = iDb;
|
||||
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
|
||||
db->mallocFailed = 1;
|
||||
sqlite3_snprintf(sizeof(zErr),zErr, "out of memory");
|
||||
}else{
|
||||
sqlite3_snprintf(sizeof(zErr),zErr, "unable to open database: %s", zFile);
|
||||
zErrDyn = sqlite3MPrintf(db, "out of memory");
|
||||
}else if( zErrDyn==0 ){
|
||||
zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
|
||||
}
|
||||
goto attach_error;
|
||||
}
|
||||
@@ -218,9 +214,6 @@ attach_error:
|
||||
if( zErrDyn ){
|
||||
sqlite3_result_error(context, zErrDyn, -1);
|
||||
sqlite3DbFree(db, zErrDyn);
|
||||
}else{
|
||||
zErr[sizeof(zErr)-1] = 0;
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
}
|
||||
if( rc ) sqlite3_result_error_code(context, rc);
|
||||
}
|
||||
@@ -412,7 +405,7 @@ int sqlite3FixInit(
|
||||
){
|
||||
sqlite3 *db;
|
||||
|
||||
if( iDb<0 || iDb==1 ) return 0;
|
||||
if( NEVER(iDb<0) || iDb==1 ) return 0;
|
||||
db = pParse->db;
|
||||
assert( db->nDb>iDb );
|
||||
pFix->pParse = pParse;
|
||||
@@ -444,7 +437,7 @@ int sqlite3FixSrcList(
|
||||
const char *zDb;
|
||||
struct SrcList_item *pItem;
|
||||
|
||||
if( pList==0 ) return 0;
|
||||
if( NEVER(pList==0) ) return 0;
|
||||
zDb = pFix->zDb;
|
||||
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
|
||||
if( pItem->zDatabase==0 ){
|
||||
|
||||
Reference in New Issue
Block a user