1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Round one of an audit for SQLITE_ENABLE_API_ARMOR for functions exposed by JNI and those functions missing armor, as [forum:5e3fc453a69b49ca|reported in several forum posts].

FossilOrigin-Name: 8c25c4b18ad07861bf0e47f99f3db04b569b9b859ad0690602f748ddf3576939
This commit is contained in:
stephan
2023-10-13 12:48:35 +00:00
parent 99d43979d3
commit 7dc0cc45f3
7 changed files with 114 additions and 50 deletions

View File

@@ -730,6 +730,9 @@ void sqlite3CloseExtensions(sqlite3 *db){
** default so as not to open security holes in older applications.
*/
int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
#ifdef SQLITE_ENABLE_API_ARMOR
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
#endif
sqlite3_mutex_enter(db->mutex);
if( onoff ){
db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc;
@@ -751,7 +754,7 @@ int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
*/
typedef struct sqlite3AutoExtList sqlite3AutoExtList;
static SQLITE_WSD struct sqlite3AutoExtList {
u32 nExt; /* Number of entries in aExt[] */
u32 nExt; /* Number of entries in aExt[] */
void (**aExt)(void); /* Pointers to the extension init functions */
} sqlite3Autoext = { 0, 0 };
@@ -779,6 +782,9 @@ int sqlite3_auto_extension(
void (*xInit)(void)
){
int rc = SQLITE_OK;
#ifdef SQLITE_ENABLE_API_ARMOR
if( xInit==0 ) return SQLITE_MISUSE_BKPT;
#endif
#ifndef SQLITE_OMIT_AUTOINIT
rc = sqlite3_initialize();
if( rc ){
@@ -831,6 +837,9 @@ int sqlite3_cancel_auto_extension(
int i;
int n = 0;
wsdAutoextInit;
#ifdef SQLITE_ENABLE_API_ARMOR
if( xInit==0 ) return 0;
#endif
sqlite3_mutex_enter(mutex);
for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
if( wsdAutoext.aExt[i]==xInit ){

View File

@@ -954,6 +954,10 @@ int sqlite3_db_cacheflush(sqlite3 *db){
int sqlite3_db_config(sqlite3 *db, int op, ...){
va_list ap;
int rc;
#ifdef SQLITE_ENABLE_API_ARMOR
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
#endif
sqlite3_mutex_enter(db->mutex);
va_start(ap, op);
switch( op ){
@@ -2365,6 +2369,12 @@ void *sqlite3_preupdate_hook(
void *pArg /* First callback argument */
){
void *pRet;
#ifdef SQLITE_ENABLE_API_ARMOR
if( db==0 || xCallback==0 ){
return;
}
#endif
sqlite3_mutex_enter(db->mutex);
pRet = db->pPreUpdateArg;
db->xPreUpdateCallback = xCallback;

View File

@@ -152,6 +152,9 @@ int sqlite3_unlock_notify(
){
int rc = SQLITE_OK;
#ifdef SQLITE_ENABLE_API_ARMOR
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
#endif
sqlite3_mutex_enter(db->mutex);
enterMutex();

View File

@@ -2029,10 +2029,16 @@ static UnpackedRecord *vdbeUnpackRecord(
** a field of the row currently being updated or deleted.
*/
int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
PreUpdate *p = db->pPreUpdate;
PreUpdate *p;
Mem *pMem;
int rc = SQLITE_OK;
#ifdef SQLITE_ENABLE_API_ARMOR
if( db==0 || ppValue==0 ){
return SQLITE_MISUSE_BKPT;
}
#endif
p = db->pPreUpdate;
/* Test that this call is being made from within an SQLITE_DELETE or
** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */
if( !p || p->op==SQLITE_INSERT ){
@@ -2093,7 +2099,12 @@ int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
** the number of columns in the row being updated, deleted or inserted.
*/
int sqlite3_preupdate_count(sqlite3 *db){
PreUpdate *p = db->pPreUpdate;
PreUpdate *p;
#ifdef SQLITE_ENABLE_API_ARMOR
p = db!=0 ? db->pPreUpdate : 0;
#else
p = db->pPreUpdate;
#endif
return (p ? p->keyinfo.nKeyField : 0);
}
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
@@ -2111,7 +2122,12 @@ int sqlite3_preupdate_count(sqlite3 *db){
** or SET DEFAULT action is considered a trigger.
*/
int sqlite3_preupdate_depth(sqlite3 *db){
PreUpdate *p = db->pPreUpdate;
PreUpdate *p;
#ifdef SQLITE_ENABLE_API_ARMOR
p = db!=0 ? db->pPreUpdate : 0;
#else
p = db->pPreUpdate;
#endif
return (p ? p->v->nFrame : 0);
}
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
@@ -2122,7 +2138,12 @@ int sqlite3_preupdate_depth(sqlite3 *db){
** only.
*/
int sqlite3_preupdate_blobwrite(sqlite3 *db){
PreUpdate *p = db->pPreUpdate;
PreUpdate *p;
#ifdef SQLITE_ENABLE_API_ARMOR
p = db!=0 ? db->pPreUpdate : 0;
#else
p = db->pPreUpdate;
#endif
return (p ? p->iBlobWrite : -1);
}
#endif
@@ -2133,10 +2154,16 @@ int sqlite3_preupdate_blobwrite(sqlite3 *db){
** a field of the row currently being updated or inserted.
*/
int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
PreUpdate *p = db->pPreUpdate;
PreUpdate *p;
int rc = SQLITE_OK;
Mem *pMem;
#ifdef SQLITE_ENABLE_API_ARMOR
if( db==0 || ppValue==0 ){
return SQLITE_MISUSE_BKPT;
}
#endif
p = db->pPreUpdate;
if( !p || p->op==SQLITE_DELETE ){
rc = SQLITE_MISUSE_BKPT;
goto preupdate_new_out;