From: drh <> Date: Thu, 16 Dec 2021 17:35:27 +0000 (+0000) Subject: New defenses against OOM and corrupt database problems in the CLI. X-Git-Tag: version-3.38.0~167 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=621a5e0c478677b938a992ee88a847a9281306fd;p=thirdparty%2Fsqlite.git New defenses against OOM and corrupt database problems in the CLI. FossilOrigin-Name: 5c9fd7fde16d8e335488b8bf5c691961d2636201b034d1f29d25de8708de291d --- diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index c9988f6078..7cdbd5968f 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -368,10 +368,11 @@ static int writeFile( mode_t mode, /* MODE parameter passed to writefile() */ sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */ ){ + if( zFile==0 ) return 1; #if !defined(_WIN32) && !defined(WIN32) if( S_ISLNK(mode) ){ const char *zTo = (const char*)sqlite3_value_text(pData); - if( symlink(zTo, zFile)<0 ) return 1; + if( zTo==0 || symlink(zTo, zFile)<0 ) return 1; }else #endif { diff --git a/ext/misc/shathree.c b/ext/misc/shathree.c index ef25cb56c6..1f100986ea 100644 --- a/ext/misc/shathree.c +++ b/ext/misc/shathree.c @@ -436,6 +436,7 @@ static void SHA3Update( unsigned int nData ){ unsigned int i = 0; + if( aData==0 ) return; #if SHA3_BYTEORDER==1234 if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){ for(; i+7iPk = sqlite3_column_int(pPkFinder, 0); zPk = (const char*)sqlite3_column_text(pPkFinder, 1); + if( zPk==0 ){ zPk = "_"; /* Defensive. Should never happen */ } } } @@ -7194,8 +7199,10 @@ static RecoverTable *recoverFindTable( if( sqlite3_stricmp(zType, "table")==0 ){ zName = (const char*)sqlite3_column_text(pStmt, 1); zSql = (const char*)sqlite3_column_text(pStmt, 2); - pRet = recoverNewTable(pRc, zName, zSql, bIntkey, nCol); - break; + if( zName!=0 && zSql!=0 ){ + pRet = recoverNewTable(pRc, zName, zSql, bIntkey, nCol); + break; + } } } @@ -7889,6 +7896,7 @@ static int do_meta_command(char *zLine, ShellState *p){ while( sqlite3_step(pStmt)==SQLITE_ROW ){ const char *zSchema = (const char *)sqlite3_column_text(pStmt,1); const char *zFile = (const char*)sqlite3_column_text(pStmt,2); + if( zSchema==0 || zFile==0 ) continue; azName = sqlite3_realloc(azName, (nName+1)*2*sizeof(char*)); shell_check_oom(azName); azName[nName*2] = strdup(zSchema); @@ -9889,6 +9897,9 @@ static int do_meta_command(char *zLine, ShellState *p){ const char *zSql = (const char*)sqlite3_column_text(pStmt, 2); const char *zAns = (const char*)sqlite3_column_text(pStmt, 3); + if( zOp==0 ) continue; + if( zSql==0 ) continue; + if( zAns==0 ) continue; k = 0; if( bVerbose>0 ){ printf("%d: %s %s\n", tno, zOp, zSql); @@ -10009,6 +10020,7 @@ static int do_meta_command(char *zLine, ShellState *p){ zSep = "VALUES("; while( SQLITE_ROW==sqlite3_step(pStmt) ){ const char *zTab = (const char*)sqlite3_column_text(pStmt,0); + if( zTab==0 ) continue; if( zLike && sqlite3_strlike(zLike, zTab, 0)!=0 ) continue; if( strncmp(zTab, "sqlite_",7)!=0 ){ appendText(&sQuery,"SELECT * FROM ", 0);