From: drh <> Date: Fri, 24 Oct 2025 12:32:32 +0000 (+0000) Subject: In the CLI, improved error messages on input errors. Limit the size of a X-Git-Tag: major-release~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc2691d5c155819b9b88bf96f8058ed0cacf4f45;p=thirdparty%2Fsqlite.git In the CLI, improved error messages on input errors. Limit the size of a single SQL statement to a little more than 2GB. FossilOrigin-Name: 0b50e7e10aae3d57f1cbd38d02be50cfbd2d5148ab4a9be712afd8678787b7bd --- diff --git a/manifest b/manifest index 2e437abe4f..2af899cdc4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Limit\sthe\ssize\sof\s--hexdb\sfiles\sin\sthe\sCLI\sto\s2\sbillion\slines,\sto\savoid\noverflowing\sthe\sline\snumber\scounter. -D 2025-10-24T09:24:56.942 +C In\sthe\sCLI,\simproved\serror\smessages\son\sinput\serrors.\s\sLimit\sthe\ssize\sof\sa\nsingle\sSQL\sstatement\sto\sa\slittle\smore\sthan\s2GB. +D 2025-10-24T12:32:32.322 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -736,7 +736,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957 -F src/shell.c.in cadd0ce691cbe9b2395ec227a4c07f1e71916493e3586ce69087efbe05b3a881 +F src/shell.c.in 8d218cb62f8badb58cb6d91302ca8b6ccdc93232dd2ba39a9ace2e41fd8495cb F src/sqlite.h.in 10faecc456d3962c7cedae70d69305f7c80129f28dd8524bd8a06b3eac955e54 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 7f236ca1b175ffe03316d974ef57df79b3938466c28d2f95caef5e08c57f3a52 @@ -1603,7 +1603,7 @@ F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 F test/shell1.test 396c04132628fe1c627fd4807a93a116f712cfb1cfe9ca5d553b1c89361a899f F test/shell2.test ab23f01ea2347e4b72bb2399af7ee82aa00f9c059141749f7c4064abca5ad728 F test/shell3.test 603b448e917537cf77be0f265c05c6f63bc677c63a533c8e96aae923b56f4a0e -F test/shell4.test ad7eee983b5e7f1dd92d8c87bc0f39474086bc32c980c00f3934c54aabc636a2 +F test/shell4.test 03593fa7908a55f255916ffeda707cdf55680c777736e3da62b1d78cde0d684d F test/shell5.test d17e7927ab8b7f720efbdd9b5d05fceb6c3c56c25917901b315400214bf24ef4 F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bdbb8 F test/shell7.test 43fd8e511c533bab5232e95c7b4be93b243451709e89582600d4b6e67693d5c3 @@ -2171,8 +2171,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b9f6ae0767ce5d9cbc6fca6d63c929f919473fa669e50a0a460627e5fde2628c -R b2b173e55eb97deac1a2191959797ec4 +P 2adfd0f47b028b8378e6cc08dc22abf1606036bbd285a7bc3a0de0eaf6feeb8f +R 1cb5603af7ab9bea0b6181cf5c07b1e1 U drh -Z 5da8f7f5471d76d7be11073cb8c00949 +Z 8148667aee325651b978014f5189e836 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1e80c94f82..2b4c46a682 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2adfd0f47b028b8378e6cc08dc22abf1606036bbd285a7bc3a0de0eaf6feeb8f +0b50e7e10aae3d57f1cbd38d02be50cfbd2d5148ab4a9be712afd8678787b7bd diff --git a/src/shell.c.in b/src/shell.c.in index 7ea45ec71a..53c1d06f29 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -5542,7 +5542,7 @@ static int showHelp(FILE *out, const char *zPattern){ } /* Forward reference */ -static int process_input(ShellState *p); +static int process_input(ShellState *p, const char*); /* ** Read the content of file zName into memory obtained from sqlite3_malloc64() @@ -10752,7 +10752,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); rc = 1; }else{ - rc = process_input(p); + rc = process_input(p, ""); pclose(p->in); } #endif @@ -10760,7 +10760,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); rc = 1; }else{ - rc = process_input(p); + rc = process_input(p, azArg[1]); fclose(p->in); } p->in = inSaved; @@ -12751,7 +12751,7 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){ ** ** Return the number of errors. */ -static int process_input(ShellState *p){ +static int process_input(ShellState *p, const char *zSrc){ char *zLine = 0; /* A single input line */ char *zSql = 0; /* Accumulated SQL text */ i64 nLine; /* Length of current line */ @@ -12764,8 +12764,8 @@ static int process_input(ShellState *p){ if( p->inputNesting==MAX_INPUT_NESTING ){ /* This will be more informative in a later version. */ - sqlite3_fprintf(stderr,"Input nesting limit (%d) reached at line %d." - " Check recursion.\n", MAX_INPUT_NESTING, p->lineno); + sqlite3_fprintf(stderr,"%s: Input nesting limit (%d) reached at line %d." + " Check recursion.\n", zSrc, MAX_INPUT_NESTING, p->lineno); return 1; } ++p->inputNesting; @@ -12830,7 +12830,15 @@ static int process_input(ShellState *p){ memcpy(zSql+nSql, zLine, nLine+1); nSql += nLine; } - if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){ + if( nSql>0x7fff0000 ){ + char zSize[100]; + sqlite3_snprintf(sizeof(zSize),zSize,"%,lld",nSql); + sqlite3_fprintf(stderr, "%s:%lld: Input SQL is too big: %s bytes\n", + zSrc, startline, zSize); + nSql = 0; + errCnt++; + break; + }else if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){ echo_group_input(p, zSql); errCnt += runOneSqlLine(p, zSql, p->in, startline); CONTINUE_PROMPT_RESET; @@ -13020,7 +13028,7 @@ static void process_sqliterc( if( stdin_is_interactive ){ sqlite3_fprintf(stderr,"-- Loading resources from %s\n", sqliterc); } - if( process_input(p) && bail_on_error ) exit(1); + if( process_input(p, sqliterc) && bail_on_error ) exit(1); fclose(p->in); }else if( sqliterc_override!=0 ){ sqlite3_fprintf(stderr,"cannot open: \"%s\"\n", sqliterc); @@ -13851,7 +13859,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ linenoiseSetCompletionCallback(linenoise_completion, NULL); #endif data.in = 0; - rc = process_input(&data); + rc = process_input(&data, ""); if( zHistory ){ shell_stifle_history(2000); shell_write_history(zHistory); @@ -13859,7 +13867,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ } }else{ data.in = stdin; - rc = process_input(&data); + rc = process_input(&data, ""); } } #ifndef SQLITE_SHELL_FIDDLE @@ -14041,7 +14049,7 @@ void fiddle_exec(const char * zSql){ if('.'==*zSql) puts(zSql); shellState.wasm.zInput = zSql; shellState.wasm.zPos = zSql; - process_input(&shellState); + process_input(&shellState, ""); shellState.wasm.zInput = shellState.wasm.zPos = 0; } } diff --git a/test/shell4.test b/test/shell4.test index 4275911ef0..3ced0702e4 100644 --- a/test/shell4.test +++ b/test/shell4.test @@ -152,6 +152,6 @@ do_test shell4-4.1 { puts $fd ".read t1.txt" close $fd catchcmd ":memory:" ".read t1.txt" -} {1 {Input nesting limit (25) reached at line 1. Check recursion.}} +} {1 {t1.txt: Input nesting limit (25) reached at line 1. Check recursion.}} finish_test