1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

In the CLI, omit the ".oom" command (only available in debug builds) and

disable the experimental ".expert" commmand in --safe mode.

FossilOrigin-Name: 5cda1f7da885afdfda8683c59e78fec8da1a05c7a4fde573e89db5f872fcfb20
This commit is contained in:
drh
2021-12-16 17:57:21 +00:00
parent 621a5e0c47
commit fe46317e26
3 changed files with 18 additions and 97 deletions

View File

@@ -1,5 +1,5 @@
C New\sdefenses\sagainst\sOOM\sand\scorrupt\sdatabase\sproblems\sin\sthe\sCLI.
D 2021-12-16T17:35:27.612
C In\sthe\sCLI,\somit\sthe\s".oom"\scommand\s(only\savailable\sin\sdebug\sbuilds)\sand\ndisable\sthe\sexperimental\s".expert"\scommmand\sin\s--safe\smode.
D 2021-12-16T17:57:21.780
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -552,7 +552,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
F src/resolve.c 4a1db4aadd802683db40ca2dbbb268187bd195f10cbdb7206dbd8ac988795571
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c a7a3d9f54eb24821ec5f67f2e5589b68a5d42d46fc5849d7376886777d93a85a
F src/shell.c.in 3f53d10076f3d0a7f993a03edec15d0ddad236536f300578cadd536e1a5b2d8c
F src/shell.c.in 6d2c65052522d964dd09c937820e6b618ee6d6f12be524390dd82c2a57b9abfd
F src/sqlite.h.in 5999d6db0e65afbd686b76cddc385b310aa3815624edba43987913067f50e209
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 8ff2fd2c166150b2e48639f5e506fb44e29f1a3f65031710b9e89d1c126ac839
@@ -1935,7 +1935,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 4d02a129c4781c97981748f3c69564e1320d8085dfba4c207e54793390cd64ab
R d166a1375475e15d05923fef18bf064e
P 5c9fd7fde16d8e335488b8bf5c691961d2636201b034d1f29d25de8708de291d
R 7feb81258c8f4748886f602fc3eeba00
U drh
Z 5bfe5520d7a9e1ead42448469dfb8bb8
Z 8a322aaf96dc4e6ca11de1635edd3a36

View File

@@ -1 +1 @@
5c9fd7fde16d8e335488b8bf5c691961d2636201b034d1f29d25de8708de291d
5cda1f7da885afdfda8683c59e78fec8da1a05c7a4fde573e89db5f872fcfb20

View File

@@ -427,15 +427,6 @@ static sqlite3 *globalDb = 0;
*/
static volatile int seenInterrupt = 0;
#ifdef SQLITE_DEBUG
/*
** Out-of-memory simulator variables
*/
static unsigned int oomCounter = 0; /* Simulate OOM when equals 1 */
static unsigned int oomRepeat = 0; /* Number of OOMs in a row */
static void*(*defaultMalloc)(int) = 0; /* The low-level malloc routine */
#endif /* SQLITE_DEBUG */
/*
** This is the name of our program. It is set in main(), used
** in a number of other places, mostly for error messages.
@@ -494,49 +485,6 @@ static void shell_check_oom(void *p){
if( p==0 ) shell_out_of_memory();
}
#ifdef SQLITE_DEBUG
/* This routine is called when a simulated OOM occurs. It is broken
** out as a separate routine to make it easy to set a breakpoint on
** the OOM
*/
void shellOomFault(void){
if( oomRepeat>0 ){
oomRepeat--;
}else{
oomCounter--;
}
}
#endif /* SQLITE_DEBUG */
#ifdef SQLITE_DEBUG
/* This routine is a replacement malloc() that is used to simulate
** Out-Of-Memory (OOM) errors for testing purposes.
*/
static void *oomMalloc(int nByte){
if( oomCounter ){
if( oomCounter==1 ){
shellOomFault();
return 0;
}else{
oomCounter--;
}
}
return defaultMalloc(nByte);
}
#endif /* SQLITE_DEBUG */
#ifdef SQLITE_DEBUG
/* Register the OOM simulator. This must occur before any memory
** allocations */
static void registerOomSimulator(void){
sqlite3_mem_methods mem;
sqlite3_config(SQLITE_CONFIG_GETMALLOC, &mem);
defaultMalloc = mem.xMalloc;
mem.xMalloc = oomMalloc;
sqlite3_config(SQLITE_CONFIG_MALLOC, &mem);
}
#endif
/*
** Write I/O traces to the following stream.
*/
@@ -4117,9 +4065,6 @@ static const char *(azHelp[]) = {
" --bom Put a UTF8 byte-order mark at the beginning",
" -e Send output to the system text editor",
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
#ifdef SQLITE_DEBUG
".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
#endif
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
" Options:",
" --append Use appendvfs to append database to the end of FILE",
@@ -8154,8 +8099,15 @@ static int do_meta_command(char *zLine, ShellState *p){
#ifndef SQLITE_OMIT_VIRTUALTABLE
if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
open_db(p, 0);
expertDotCommand(p, azArg, nArg);
if( p->bSafeMode ){
raw_printf(stderr,
"Cannot run experimental commands such as \"%s\" in safe mode\n",
azArg[0]);
rc = 1;
}else{
open_db(p, 0);
expertDotCommand(p, azArg, nArg);
}
}else
#endif
@@ -8947,7 +8899,8 @@ static int do_meta_command(char *zLine, ShellState *p){
raw_printf(stderr, "Usage: .nonce NONCE\n");
rc = 1;
}else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
raw_printf(stderr, "line %d: incorrect nonce: \"%s\"\n", p->lineno, azArg[1]);
raw_printf(stderr, "line %d: incorrect nonce: \"%s\"\n",
p->lineno, azArg[1]);
exit(1);
}else{
p->bSafeMode = 0;
@@ -8966,34 +8919,6 @@ static int do_meta_command(char *zLine, ShellState *p){
}
}else
#ifdef SQLITE_DEBUG
if( c=='o' && strcmp(azArg[0],"oom")==0 ){
int i;
for(i=1; i<nArg; i++){
const char *z = azArg[i];
if( z[0]=='-' && z[1]=='-' ) z++;
if( strcmp(z,"-repeat")==0 ){
if( i==nArg-1 ){
raw_printf(p->out, "missing argument on \"%s\"\n", azArg[i]);
rc = 1;
}else{
oomRepeat = (int)integerValue(azArg[++i]);
}
}else if( IsDigit(z[0]) ){
oomCounter = (int)integerValue(azArg[i]);
}else{
raw_printf(p->out, "unknown argument: \"%s\"\n", azArg[i]);
raw_printf(p->out, "Usage: .oom [--repeat N] [M]\n");
rc = 1;
}
}
if( rc==0 ){
raw_printf(p->out, "oomCounter = %d\n", oomCounter);
raw_printf(p->out, "oomRepeat = %d\n", oomRepeat);
}
}else
#endif /* SQLITE_DEBUG */
if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
const char *zFN = 0; /* Pointer to constant filename */
char *zNewFilename = 0; /* Name of the database file to open */
@@ -11330,10 +11255,6 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
stdin_is_interactive = isatty(0);
stdout_is_console = isatty(1);
#ifdef SQLITE_DEBUG
registerOomSimulator();
#endif
#if !defined(_WIN32_WCE)
if( getenv("SQLITE_DEBUG_BREAK") ){
if( isatty(0) && isatty(2) ){