From: dan Date: Wed, 25 May 2011 18:46:22 +0000 (+0000) Subject: Fix a case where a malloc() error could lead to mismatched virtual-table xBegin/xComm... X-Git-Tag: version-3.7.7~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2cac2078f6afd8fb6d262293029e12f9c235a130;p=thirdparty%2Fsqlite.git Fix a case where a malloc() error could lead to mismatched virtual-table xBegin/xCommit/xRollback callbacks. FossilOrigin-Name: d807304a695fc85402b86e1cd32a6e3bbb2823c8 --- diff --git a/manifest b/manifest index a7124cf8a8..1074285b3f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scompiler\swarning. -D 2011-05-25T15:54:09.204 +C Fix\sa\scase\swhere\sa\smalloc()\serror\scould\slead\sto\smismatched\svirtual-table\sxBegin/xCommit/xRollback\scallbacks. +D 2011-05-25T18:46:22.024 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 11dcc00a8d0e5202def00e81732784fb0cc4fe1d F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -244,7 +244,7 @@ F src/vdbeaux.c 07a5226ae6e9c6e54b5fcd3c395b86e7ffdba3a4 F src/vdbeblob.c c3ccb7c8732858c680f442932e66ad06bb036562 F src/vdbemem.c 0498796b6ffbe45e32960d6a1f5adfb6e419883b F src/vdbetrace.c 5d0dc3d5fd54878cc8d6d28eb41deb8d5885b114 -F src/vtab.c 6bff354033de8eff72f42565411a72a84fd2b26b +F src/vtab.c 9ba8c7fdb7d39260c033a402f6032d3e7bc5d336 F src/wal.c de27c34c8016c00be348fc6bed588816557ceb66 F src/wal.h 66b40bd91bc29a5be1c88ddd1f5ade8f3f48728a F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f @@ -938,7 +938,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 92f26a8b8f18832cb1f8ba7dd8e5b020e71a5883 -R 1179d31eff61655636edf672584723cf -U drh -Z c44adff51be44d9f0cc2862535697c61 +P 6df99e52dabf2a243ad635529649b86c21735e91 +R 02c26b8fd230a540c57276590c974e79 +U dan +Z e2a23225f8e5abceac6a8fe1d14982ec diff --git a/manifest.uuid b/manifest.uuid index e2dc48d525..5b49fb4d2d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6df99e52dabf2a243ad635529649b86c21735e91 \ No newline at end of file +d807304a695fc85402b86e1cd32a6e3bbb2823c8 \ No newline at end of file diff --git a/src/vtab.c b/src/vtab.c index 0a4c9ea0a4..dffd6a2664 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -577,11 +577,11 @@ int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){ return rc; } - /* -** Add the virtual table pVTab to the array sqlite3.aVTrans[]. +** Grow the db->aVTrans[] array so that there is room for at least one +** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise. */ -static int addToVTrans(sqlite3 *db, VTable *pVTab){ +static int growVTrans(sqlite3 *db){ const int ARRAY_INCR = 5; /* Grow the sqlite3.aVTrans array if required */ @@ -596,10 +596,17 @@ static int addToVTrans(sqlite3 *db, VTable *pVTab){ db->aVTrans = aVTrans; } + return SQLITE_OK; +} + +/* +** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should +** have already been reserved using growVTrans(). +*/ +static void addToVTrans(sqlite3 *db, VTable *pVTab){ /* Add pVtab to the end of sqlite3.aVTrans */ db->aVTrans[db->nVTrans++] = pVTab; sqlite3VtabLock(pVTab); - return SQLITE_OK; } /* @@ -637,7 +644,10 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ /* Justification of ALWAYS(): The xConstructor method is required to ** create a valid sqlite3_vtab if it returns SQLITE_OK. */ if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){ - rc = addToVTrans(db, sqlite3GetVTable(db, pTab)); + rc = growVTrans(db); + if( rc==SQLITE_OK ){ + addToVTrans(db, sqlite3GetVTable(db, pTab)); + } } return rc; @@ -843,10 +853,14 @@ int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){ } } - /* Invoke the xBegin method */ - rc = pModule->xBegin(pVTab->pVtab); + /* Invoke the xBegin method. If successful, add the vtab to the + ** sqlite3.aVTrans[] array. */ + rc = growVTrans(db); if( rc==SQLITE_OK ){ - rc = addToVTrans(db, pVTab); + rc = pModule->xBegin(pVTab->pVtab); + if( rc==SQLITE_OK ){ + addToVTrans(db, pVTab); + } } } return rc;