From: drh <> Date: Mon, 6 Dec 2021 16:36:37 +0000 (+0000) Subject: In the shell tool, avoid modifying internal data structures until after the arguments... X-Git-Tag: version-3.37.1~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=764d1809ce1de85d77d9db6a23e4c4b40951c0ad;p=thirdparty%2Fsqlite.git In the shell tool, avoid modifying internal data structures until after the arguments to ".open" have been parsed. FossilOrigin-Name: cbd69ed8afd3facda39fe8c81a3e8e4a1928923bcfd93e99d1bb8b3868ef3e5b --- diff --git a/manifest b/manifest index f67fa04153..af75137a65 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Start\sa\snew\sbranch\son\swhich\sto\scherrypick\sfixes\sagainst\s3.37.0. -D 2021-12-06T16:29:53.928 +C In\sthe\sshell\stool,\savoid\smodifying\sinternal\sdata\sstructures\suntil\safter\sthe\sarguments\sto\s".open"\shave\sbeen\sparsed. +D 2021-12-06T16:36:37.667 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -551,7 +551,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 975f268ef261773fcbed1e519dfa10c4f33e8b1cffc12120563e61857fff07c6 +F src/shell.c.in e7ee6517544d075d9f06ee2571567026b89cf9fbeef16a74918019b1cb425764 F src/sqlite.h.in 5cd209ac7dc4180f0e19292846f40440b8488015849ca0110c70b906b57d68f0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8ff2fd2c166150b2e48639f5e506fb44e29f1a3f65031710b9e89d1c126ac839 @@ -1933,10 +1933,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bd41822c7424d393a30e92ff6cb254d25c26769889c1499a18a0b9339f5d6c8a -R cdbd66aa01718c358cf2d24b75827502 -T *branch * branch-3.37 -T *sym-branch-3.37 * -T -sym-trunk * +P cea9e41aaee9b43496909fa2ba80dddaee1dd77d44bcb4d8d38034d1b003d762 +Q +fcc509d325dabe06275e7804183bb8b4ba6470a45b443bc8292eecd0974e6367 +R 29ff6f0ab37b56a9972cccaffdc627cd U drh -Z 3234c55974413333201859e4e65b8d8f +Z a94d193d2ea331fde75cdd8dc9044784 diff --git a/manifest.uuid b/manifest.uuid index ca3d67c624..f72a3cbb67 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cea9e41aaee9b43496909fa2ba80dddaee1dd77d44bcb4d8d38034d1b003d762 \ No newline at end of file +cbd69ed8afd3facda39fe8c81a3e8e4a1928923bcfd93e99d1bb8b3868ef3e5b \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index b4b4e2fcce..72fe26339e 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8941,16 +8941,8 @@ static int do_meta_command(char *zLine, ShellState *p){ char *zNewFilename = 0; /* Name of the database file to open */ int iName = 1; /* Index in azArg[] of the filename */ int newFlag = 0; /* True to delete file before opening */ - /* Close the existing database */ - session_close_all(p, -1); - close_db(p->db); - p->db = 0; - p->pAuxDb->zDbFilename = 0; - sqlite3_free(p->pAuxDb->zFreeOnClose); - p->pAuxDb->zFreeOnClose = 0; - p->openMode = SHELL_OPEN_UNSPEC; - p->openFlags = 0; - p->szMax = 0; + int openMode = SHELL_OPEN_UNSPEC; + /* Check for command-line arguments */ for(iName=1; iNameopenMode = SHELL_OPEN_ZIPFILE; + openMode = SHELL_OPEN_ZIPFILE; #endif }else if( optionMatch(z, "append") ){ - p->openMode = SHELL_OPEN_APPENDVFS; + openMode = SHELL_OPEN_APPENDVFS; }else if( optionMatch(z, "readonly") ){ - p->openMode = SHELL_OPEN_READONLY; + openMode = SHELL_OPEN_READONLY; }else if( optionMatch(z, "nofollow") ){ p->openFlags |= SQLITE_OPEN_NOFOLLOW; #ifndef SQLITE_OMIT_DESERIALIZE }else if( optionMatch(z, "deserialize") ){ - p->openMode = SHELL_OPEN_DESERIALIZE; + openMode = SHELL_OPEN_DESERIALIZE; }else if( optionMatch(z, "hexdb") ){ - p->openMode = SHELL_OPEN_HEXDB; + openMode = SHELL_OPEN_HEXDB; }else if( optionMatch(z, "maxsize") && iName+1szMax = integerValue(azArg[++iName]); #endif /* SQLITE_OMIT_DESERIALIZE */ @@ -8986,6 +8978,18 @@ static int do_meta_command(char *zLine, ShellState *p){ zNewFilename = sqlite3_mprintf("%s", z); } } + + /* Close the existing database */ + session_close_all(p, -1); + close_db(p->db); + p->db = 0; + p->pAuxDb->zDbFilename = 0; + sqlite3_free(p->pAuxDb->zFreeOnClose); + p->pAuxDb->zFreeOnClose = 0; + p->openMode = openMode; + p->openFlags = 0; + p->szMax = 0; + /* If a filename is specified, try to open it first */ if( zNewFilename || p->openMode==SHELL_OPEN_HEXDB ){ if( newFlag && !p->bSafeMode ) shellDeleteFile(zNewFilename);