diff options
author | larrybr <larrybr@noemail.net> | 2023-04-22 16:46:38 +0000 |
---|---|---|
committer | larrybr <larrybr@noemail.net> | 2023-04-22 16:46:38 +0000 |
commit | e945b293596fe09390c89c0749979979514d68de (patch) | |
tree | 7aa5c016c8a25e7983cd6d4f21a32c24ddfdfd37 /src | |
parent | a9c4c82ef1197681bb78a4ea1c996fc678fa3e3e (diff) | |
download | sqlite-e945b293596fe09390c89c0749979979514d68de.tar.gz sqlite-e945b293596fe09390c89c0749979979514d68de.zip |
Add --unsafe-testing invocation option to CLI. Needs some tests added and changed.
FossilOrigin-Name: b3d9ac052d5c2dd1afeeeb5c9cfac9dd91a1b8d6a74a2ef10aa2037ca505abce
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index 343e03c3a..c6007c5e7 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1526,6 +1526,7 @@ static ShellState shellState; #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */ #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */ #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */ +#define SHFLG_TestingMode 0x00000400 /* allow unsafe testing features */ /* ** Macros for testing and setting shellFlgs @@ -5351,6 +5352,13 @@ static void open_db(ShellState *p, int openFlags){ } sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); + /* Reflect the use or absence of --unsafe-testing invocation. */ + { + int testmode_on = ShellHasFlag(p,SHFLG_TestingMode); + sqlite3_db_config(p->db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, testmode_on,0); + sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, !testmode_on,0); + } + #ifndef SQLITE_OMIT_LOAD_EXTENSION sqlite3_enable_load_extension(p->db, 1); #endif @@ -8960,6 +8968,12 @@ static int do_meta_command(char *zLine, ShellState *p){ int isWO = 0; /* True if making an imposter of a WITHOUT ROWID table */ int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */ int i; + if( !ShellHasFlag(p,SHFLG_TestingMode) ){ + utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n", + "imposter"); + rc = 1; + goto meta_command_exit; + } if( !(nArg==3 || (nArg==2 && sqlite3_stricmp(azArg[1],"off")==0)) ){ utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n" " .imposter off\n"); @@ -10759,6 +10773,12 @@ static int do_meta_command(char *zLine, ShellState *p){ int i, n2; const char *zCmd = 0; + if( !ShellHasFlag(p,SHFLG_TestingMode) ){ + utf8_printf(stderr, ".%s unavailable without --unsafe-testing\n", + "testctrl"); + rc = 1; + goto meta_command_exit; + } open_db(p, 0); zCmd = nArg>=2 ? azArg[1] : "help"; @@ -11758,6 +11778,7 @@ static const char zOptions[] = " -stats print memory stats before each finalize\n" " -table set output mode to 'table'\n" " -tabs set output mode to 'tabs'\n" + " -unsafe-testing allow unsafe commands and modes for testing\n" #if SHELL_WIN_UTF8_OPT " -utf8 setup interactive console code page for UTF-8\n" #endif @@ -12138,6 +12159,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( cli_strcmp(z,"-nonce")==0 ){ free(data.zNonce); data.zNonce = strdup(argv[++i]); + }else if( cli_strcmp(z,"-unsafe-testing")==0 ){ + ShellSetFlag(&data,SHFLG_TestingMode); }else if( cli_strcmp(z,"-safe")==0 ){ /* no-op - catch this on the second pass */ } @@ -12374,6 +12397,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #endif }else if( cli_strcmp(z,"-safe")==0 ){ data.bSafeMode = data.bSafeModePersist = 1; + }else if( cli_strcmp(z,"-unsafe-testing")==0 ){ + /* Acted upon in first pass. */ }else{ utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); raw_printf(stderr,"Use -help for a list of options.\n"); |