Fossil SCM

Update the built-in SQLite with the fix for the broken shadow table protections.

drh 2021-11-04 00:59 trunk
Commit 00650cf0208528e12131a06c3e7fe0bfb0e0d09595ed5fdd618fd2a3232d0776
2 files changed +47 -16 +1 -1
+47 -16
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.37.0"
456456
#define SQLITE_VERSION_NUMBER 3037000
457
-#define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
457
+#define SQLITE_SOURCE_ID "2021-11-04 00:51:53 005a8642773556825fe4c5d0b2c12517d35289308a30df0151ef7f080acb0172"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -19987,13 +19987,15 @@
1998719987
#endif
1998819988
SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
1998919989
#ifndef SQLITE_OMIT_VIRTUALTABLE
1999019990
SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
1999119991
SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
19992
+SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*);
1999219993
#else
1999319994
# define sqlite3ShadowTableName(A,B) 0
1999419995
# define sqlite3IsShadowTableOf(A,B,C) 0
19996
+# define sqlite3MarkAllShadowTablesOf(A,B)
1999519997
#endif
1999619998
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
1999719999
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
1999820000
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
1999920001
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -115365,10 +115367,44 @@
115365115367
if( pMod->pModule->xShadowName==0 ) return 0;
115366115368
return pMod->pModule->xShadowName(zName+nName+1);
115367115369
}
115368115370
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
115369115371
115372
+#ifndef SQLITE_OMIT_VIRTUALTABLE
115373
+/*
115374
+** Table pTab is a virtual table. If it the virtual table implementation
115375
+** exists and has an xShadowName method, then loop over all other ordinary
115376
+** tables within the same schema looking for shadow tables of pTab, and mark
115377
+** any shadow tables seen using the TF_Shadow flag.
115378
+*/
115379
+SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3 *db, Table *pTab){
115380
+ int nName; /* Length of pTab->zName */
115381
+ Module *pMod; /* Module for the virtual table */
115382
+ HashElem *k; /* For looping through the symbol table */
115383
+
115384
+ assert( IsVirtual(pTab) );
115385
+ pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
115386
+ if( pMod==0 ) return;
115387
+ if( NEVER(pMod->pModule==0) ) return;
115388
+ if( pMod->pModule->xShadowName==0 ) return;
115389
+ assert( pTab->zName!=0 );
115390
+ nName = sqlite3Strlen30(pTab->zName);
115391
+ for(k=sqliteHashFirst(&pTab->pSchema->tblHash); k; k=sqliteHashNext(k)){
115392
+ Table *pOther = sqliteHashData(k);
115393
+ assert( pOther->zName!=0 );
115394
+ if( !IsOrdinaryTable(pOther) ) continue;
115395
+ if( pOther->tabFlags & TF_Shadow ) continue;
115396
+ if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0
115397
+ && pOther->zName[nName]=='_'
115398
+ && pMod->pModule->xShadowName(pOther->zName+nName+1)
115399
+ ){
115400
+ pOther->tabFlags |= TF_Shadow;
115401
+ }
115402
+ }
115403
+}
115404
+#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
115405
+
115370115406
#ifndef SQLITE_OMIT_VIRTUALTABLE
115371115407
/*
115372115408
** Return true if zName is a shadow table name in the current database
115373115409
** connection.
115374115410
**
@@ -115879,17 +115915,16 @@
115879115915
#endif
115880115916
115881115917
assert( pTable );
115882115918
115883115919
#ifndef SQLITE_OMIT_VIRTUALTABLE
115884
- db->nSchemaLock++;
115885
- rc = sqlite3VtabCallConnect(pParse, pTable);
115886
- db->nSchemaLock--;
115887
- if( rc ){
115888
- return 1;
115920
+ if( IsVirtual(pTable) ){
115921
+ db->nSchemaLock++;
115922
+ rc = sqlite3VtabCallConnect(pParse, pTable);
115923
+ db->nSchemaLock--;
115924
+ return rc;
115889115925
}
115890
- if( IsVirtual(pTable) ) return 0;
115891115926
#endif
115892115927
115893115928
#ifndef SQLITE_OMIT_VIEW
115894115929
/* A positive nCol means the columns names for this view are
115895115930
** already known.
@@ -144727,22 +144762,18 @@
144727144762
sqlite3DbFree(db, zStmt);
144728144763
144729144764
iReg = ++pParse->nMem;
144730144765
sqlite3VdbeLoadString(v, iReg, pTab->zName);
144731144766
sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
144732
- }
144733
-
144734
- /* If we are rereading the sqlite_schema table create the in-memory
144735
- ** record of the table. The xConnect() method is not called until
144736
- ** the first time the virtual table is used in an SQL statement. This
144737
- ** allows a schema that contains virtual tables to be loaded before
144738
- ** the required virtual table implementations are registered. */
144739
- else {
144767
+ }else{
144768
+ /* If we are rereading the sqlite_schema table create the in-memory
144769
+ ** record of the table. */
144740144770
Table *pOld;
144741144771
Schema *pSchema = pTab->pSchema;
144742144772
const char *zName = pTab->zName;
144743
- assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
144773
+ assert( zName!=0 );
144774
+ sqlite3MarkAllShadowTablesOf(db, pTab);
144744144775
pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab);
144745144776
if( pOld ){
144746144777
sqlite3OomFault(db);
144747144778
assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
144748144779
return;
144749144780
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -19987,13 +19987,15 @@
19987 #endif
19988 SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
19989 #ifndef SQLITE_OMIT_VIRTUALTABLE
19990 SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
19991 SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
 
19992 #else
19993 # define sqlite3ShadowTableName(A,B) 0
19994 # define sqlite3IsShadowTableOf(A,B,C) 0
 
19995 #endif
19996 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
19997 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
19998 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
19999 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -115365,10 +115367,44 @@
115365 if( pMod->pModule->xShadowName==0 ) return 0;
115366 return pMod->pModule->xShadowName(zName+nName+1);
115367 }
115368 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
115369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115370 #ifndef SQLITE_OMIT_VIRTUALTABLE
115371 /*
115372 ** Return true if zName is a shadow table name in the current database
115373 ** connection.
115374 **
@@ -115879,17 +115915,16 @@
115879 #endif
115880
115881 assert( pTable );
115882
115883 #ifndef SQLITE_OMIT_VIRTUALTABLE
115884 db->nSchemaLock++;
115885 rc = sqlite3VtabCallConnect(pParse, pTable);
115886 db->nSchemaLock--;
115887 if( rc ){
115888 return 1;
115889 }
115890 if( IsVirtual(pTable) ) return 0;
115891 #endif
115892
115893 #ifndef SQLITE_OMIT_VIEW
115894 /* A positive nCol means the columns names for this view are
115895 ** already known.
@@ -144727,22 +144762,18 @@
144727 sqlite3DbFree(db, zStmt);
144728
144729 iReg = ++pParse->nMem;
144730 sqlite3VdbeLoadString(v, iReg, pTab->zName);
144731 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
144732 }
144733
144734 /* If we are rereading the sqlite_schema table create the in-memory
144735 ** record of the table. The xConnect() method is not called until
144736 ** the first time the virtual table is used in an SQL statement. This
144737 ** allows a schema that contains virtual tables to be loaded before
144738 ** the required virtual table implementations are registered. */
144739 else {
144740 Table *pOld;
144741 Schema *pSchema = pTab->pSchema;
144742 const char *zName = pTab->zName;
144743 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
 
144744 pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab);
144745 if( pOld ){
144746 sqlite3OomFault(db);
144747 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
144748 return;
144749
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-11-04 00:51:53 005a8642773556825fe4c5d0b2c12517d35289308a30df0151ef7f080acb0172"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -19987,13 +19987,15 @@
19987 #endif
19988 SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db);
19989 #ifndef SQLITE_OMIT_VIRTUALTABLE
19990 SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
19991 SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
19992 SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*);
19993 #else
19994 # define sqlite3ShadowTableName(A,B) 0
19995 # define sqlite3IsShadowTableOf(A,B,C) 0
19996 # define sqlite3MarkAllShadowTablesOf(A,B)
19997 #endif
19998 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
19999 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
20000 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
20001 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
@@ -115365,10 +115367,44 @@
115367 if( pMod->pModule->xShadowName==0 ) return 0;
115368 return pMod->pModule->xShadowName(zName+nName+1);
115369 }
115370 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
115371
115372 #ifndef SQLITE_OMIT_VIRTUALTABLE
115373 /*
115374 ** Table pTab is a virtual table. If it the virtual table implementation
115375 ** exists and has an xShadowName method, then loop over all other ordinary
115376 ** tables within the same schema looking for shadow tables of pTab, and mark
115377 ** any shadow tables seen using the TF_Shadow flag.
115378 */
115379 SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3 *db, Table *pTab){
115380 int nName; /* Length of pTab->zName */
115381 Module *pMod; /* Module for the virtual table */
115382 HashElem *k; /* For looping through the symbol table */
115383
115384 assert( IsVirtual(pTab) );
115385 pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]);
115386 if( pMod==0 ) return;
115387 if( NEVER(pMod->pModule==0) ) return;
115388 if( pMod->pModule->xShadowName==0 ) return;
115389 assert( pTab->zName!=0 );
115390 nName = sqlite3Strlen30(pTab->zName);
115391 for(k=sqliteHashFirst(&pTab->pSchema->tblHash); k; k=sqliteHashNext(k)){
115392 Table *pOther = sqliteHashData(k);
115393 assert( pOther->zName!=0 );
115394 if( !IsOrdinaryTable(pOther) ) continue;
115395 if( pOther->tabFlags & TF_Shadow ) continue;
115396 if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0
115397 && pOther->zName[nName]=='_'
115398 && pMod->pModule->xShadowName(pOther->zName+nName+1)
115399 ){
115400 pOther->tabFlags |= TF_Shadow;
115401 }
115402 }
115403 }
115404 #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
115405
115406 #ifndef SQLITE_OMIT_VIRTUALTABLE
115407 /*
115408 ** Return true if zName is a shadow table name in the current database
115409 ** connection.
115410 **
@@ -115879,17 +115915,16 @@
115915 #endif
115916
115917 assert( pTable );
115918
115919 #ifndef SQLITE_OMIT_VIRTUALTABLE
115920 if( IsVirtual(pTable) ){
115921 db->nSchemaLock++;
115922 rc = sqlite3VtabCallConnect(pParse, pTable);
115923 db->nSchemaLock--;
115924 return rc;
115925 }
 
115926 #endif
115927
115928 #ifndef SQLITE_OMIT_VIEW
115929 /* A positive nCol means the columns names for this view are
115930 ** already known.
@@ -144727,22 +144762,18 @@
144762 sqlite3DbFree(db, zStmt);
144763
144764 iReg = ++pParse->nMem;
144765 sqlite3VdbeLoadString(v, iReg, pTab->zName);
144766 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
144767 }else{
144768 /* If we are rereading the sqlite_schema table create the in-memory
144769 ** record of the table. */
 
 
 
 
 
144770 Table *pOld;
144771 Schema *pSchema = pTab->pSchema;
144772 const char *zName = pTab->zName;
144773 assert( zName!=0 );
144774 sqlite3MarkAllShadowTablesOf(db, pTab);
144775 pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab);
144776 if( pOld ){
144777 sqlite3OomFault(db);
144778 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
144779 return;
144780
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.37.0"
150150
#define SQLITE_VERSION_NUMBER 3037000
151
-#define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
151
+#define SQLITE_SOURCE_ID "2021-11-04 00:51:53 005a8642773556825fe4c5d0b2c12517d35289308a30df0151ef7f080acb0172"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-11-03 16:35:23 3206edff947b9edb485466f05b2baadf725d798229630c7e83e88c0b9ae278ca"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-11-04 00:51:53 005a8642773556825fe4c5d0b2c12517d35289308a30df0151ef7f080acb0172"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button