Fossil SCM

Ensure that db_open()'s db-is-an-appendvfs-binary check uses canonicalized filenames to avoid the problem reported in [forum:16880a28aad1a868 | forum post 16880a28aad1a868].

stephan 2022-03-01 21:02 trunk merge
Commit ab7ad2348c1a357c04d19c9bbaf57aba3f40c7bade3034c5633d793b0397017f
3 files changed +8 -1 +8 -1 +1 -9
+8 -1
--- src/db.c
+++ src/db.c
@@ -1635,19 +1635,26 @@
16351635
** connection. An error results in process abort.
16361636
*/
16371637
LOCAL sqlite3 *db_open(const char *zDbName){
16381638
int rc;
16391639
sqlite3 *db;
1640
+ Blob bNameCheck = BLOB_INITIALIZER;
16401641
16411642
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
1642
- if( strcmp(zDbName, g.nameOfExe)==0 ){
1643
+ file_canonical_name(zDbName, &bNameCheck, 0)
1644
+ /* For purposes of the apndvfs check, g.nameOfExe and zDbName must
1645
+ ** both be canonicalized, else chances are very good that they
1646
+ ** will not match even if they're the same file. Details:
1647
+ ** https://fossil-scm.org/forum/forumpost/16880a28aad1a868 */;
1648
+ if( strcmp(blob_str(&bNameCheck), g.nameOfExe)==0 ){
16431649
extern int sqlite3_appendvfs_init(
16441650
sqlite3 *, char **, const sqlite3_api_routines *
16451651
);
16461652
sqlite3_appendvfs_init(0,0,0);
16471653
g.zVfsName = "apndvfs";
16481654
}
1655
+ blob_zero(&bNameCheck);
16491656
rc = sqlite3_open_v2(
16501657
zDbName, &db,
16511658
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
16521659
g.zVfsName
16531660
);
16541661
--- src/db.c
+++ src/db.c
@@ -1635,19 +1635,26 @@
1635 ** connection. An error results in process abort.
1636 */
1637 LOCAL sqlite3 *db_open(const char *zDbName){
1638 int rc;
1639 sqlite3 *db;
 
1640
1641 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
1642 if( strcmp(zDbName, g.nameOfExe)==0 ){
 
 
 
 
 
1643 extern int sqlite3_appendvfs_init(
1644 sqlite3 *, char **, const sqlite3_api_routines *
1645 );
1646 sqlite3_appendvfs_init(0,0,0);
1647 g.zVfsName = "apndvfs";
1648 }
 
1649 rc = sqlite3_open_v2(
1650 zDbName, &db,
1651 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
1652 g.zVfsName
1653 );
1654
--- src/db.c
+++ src/db.c
@@ -1635,19 +1635,26 @@
1635 ** connection. An error results in process abort.
1636 */
1637 LOCAL sqlite3 *db_open(const char *zDbName){
1638 int rc;
1639 sqlite3 *db;
1640 Blob bNameCheck = BLOB_INITIALIZER;
1641
1642 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
1643 file_canonical_name(zDbName, &bNameCheck, 0)
1644 /* For purposes of the apndvfs check, g.nameOfExe and zDbName must
1645 ** both be canonicalized, else chances are very good that they
1646 ** will not match even if they're the same file. Details:
1647 ** https://fossil-scm.org/forum/forumpost/16880a28aad1a868 */;
1648 if( strcmp(blob_str(&bNameCheck), g.nameOfExe)==0 ){
1649 extern int sqlite3_appendvfs_init(
1650 sqlite3 *, char **, const sqlite3_api_routines *
1651 );
1652 sqlite3_appendvfs_init(0,0,0);
1653 g.zVfsName = "apndvfs";
1654 }
1655 blob_zero(&bNameCheck);
1656 rc = sqlite3_open_v2(
1657 zDbName, &db,
1658 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
1659 g.zVfsName
1660 );
1661
+8 -1
--- src/db.c
+++ src/db.c
@@ -1635,19 +1635,26 @@
16351635
** connection. An error results in process abort.
16361636
*/
16371637
LOCAL sqlite3 *db_open(const char *zDbName){
16381638
int rc;
16391639
sqlite3 *db;
1640
+ Blob bNameCheck = BLOB_INITIALIZER;
16401641
16411642
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
1642
- if( strcmp(zDbName, g.nameOfExe)==0 ){
1643
+ file_canonical_name(zDbName, &bNameCheck, 0)
1644
+ /* For purposes of the apndvfs check, g.nameOfExe and zDbName must
1645
+ ** both be canonicalized, else chances are very good that they
1646
+ ** will not match even if they're the same file. Details:
1647
+ ** https://fossil-scm.org/forum/forumpost/16880a28aad1a868 */;
1648
+ if( strcmp(blob_str(&bNameCheck), g.nameOfExe)==0 ){
16431649
extern int sqlite3_appendvfs_init(
16441650
sqlite3 *, char **, const sqlite3_api_routines *
16451651
);
16461652
sqlite3_appendvfs_init(0,0,0);
16471653
g.zVfsName = "apndvfs";
16481654
}
1655
+ blob_zero(&bNameCheck);
16491656
rc = sqlite3_open_v2(
16501657
zDbName, &db,
16511658
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
16521659
g.zVfsName
16531660
);
16541661
--- src/db.c
+++ src/db.c
@@ -1635,19 +1635,26 @@
1635 ** connection. An error results in process abort.
1636 */
1637 LOCAL sqlite3 *db_open(const char *zDbName){
1638 int rc;
1639 sqlite3 *db;
 
1640
1641 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
1642 if( strcmp(zDbName, g.nameOfExe)==0 ){
 
 
 
 
 
1643 extern int sqlite3_appendvfs_init(
1644 sqlite3 *, char **, const sqlite3_api_routines *
1645 );
1646 sqlite3_appendvfs_init(0,0,0);
1647 g.zVfsName = "apndvfs";
1648 }
 
1649 rc = sqlite3_open_v2(
1650 zDbName, &db,
1651 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
1652 g.zVfsName
1653 );
1654
--- src/db.c
+++ src/db.c
@@ -1635,19 +1635,26 @@
1635 ** connection. An error results in process abort.
1636 */
1637 LOCAL sqlite3 *db_open(const char *zDbName){
1638 int rc;
1639 sqlite3 *db;
1640 Blob bNameCheck = BLOB_INITIALIZER;
1641
1642 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
1643 file_canonical_name(zDbName, &bNameCheck, 0)
1644 /* For purposes of the apndvfs check, g.nameOfExe and zDbName must
1645 ** both be canonicalized, else chances are very good that they
1646 ** will not match even if they're the same file. Details:
1647 ** https://fossil-scm.org/forum/forumpost/16880a28aad1a868 */;
1648 if( strcmp(blob_str(&bNameCheck), g.nameOfExe)==0 ){
1649 extern int sqlite3_appendvfs_init(
1650 sqlite3 *, char **, const sqlite3_api_routines *
1651 );
1652 sqlite3_appendvfs_init(0,0,0);
1653 g.zVfsName = "apndvfs";
1654 }
1655 blob_zero(&bNameCheck);
1656 rc = sqlite3_open_v2(
1657 zDbName, &db,
1658 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
1659 g.zVfsName
1660 );
1661
+1 -9
--- src/main.c
+++ src/main.c
@@ -420,28 +420,20 @@
420420
unsigned int nArg; /* Number of new arguments */
421421
char *z; /* General use string pointer */
422422
char **newArgv; /* New expanded g.argv under construction */
423423
const char *zFileName; /* input file name */
424424
FILE *inFile; /* input FILE */
425
-#if defined(_WIN32)
426
- wchar_t buf[MAX_PATH];
427
-#endif
428425
429426
g.argc = argc;
430427
g.argv = argv;
431428
sqlite3_initialize();
432429
#if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
433430
for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
434431
#else
435432
for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
436433
#endif
437
-#if defined(_WIN32)
438
- GetModuleFileNameW(NULL, buf, MAX_PATH);
439
- g.nameOfExe = fossil_path_to_utf8(buf);
440
-#else
441
- g.nameOfExe = g.argv[0];
442
-#endif
434
+ g.nameOfExe = file_fullexename(g.argv[0]);
443435
for(i=1; i<g.argc-1; i++){
444436
z = g.argv[i];
445437
if( z[0]!='-' ) continue;
446438
z++;
447439
if( z[0]=='-' ) z++;
448440
--- src/main.c
+++ src/main.c
@@ -420,28 +420,20 @@
420 unsigned int nArg; /* Number of new arguments */
421 char *z; /* General use string pointer */
422 char **newArgv; /* New expanded g.argv under construction */
423 const char *zFileName; /* input file name */
424 FILE *inFile; /* input FILE */
425 #if defined(_WIN32)
426 wchar_t buf[MAX_PATH];
427 #endif
428
429 g.argc = argc;
430 g.argv = argv;
431 sqlite3_initialize();
432 #if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
433 for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
434 #else
435 for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
436 #endif
437 #if defined(_WIN32)
438 GetModuleFileNameW(NULL, buf, MAX_PATH);
439 g.nameOfExe = fossil_path_to_utf8(buf);
440 #else
441 g.nameOfExe = g.argv[0];
442 #endif
443 for(i=1; i<g.argc-1; i++){
444 z = g.argv[i];
445 if( z[0]!='-' ) continue;
446 z++;
447 if( z[0]=='-' ) z++;
448
--- src/main.c
+++ src/main.c
@@ -420,28 +420,20 @@
420 unsigned int nArg; /* Number of new arguments */
421 char *z; /* General use string pointer */
422 char **newArgv; /* New expanded g.argv under construction */
423 const char *zFileName; /* input file name */
424 FILE *inFile; /* input FILE */
 
 
 
425
426 g.argc = argc;
427 g.argv = argv;
428 sqlite3_initialize();
429 #if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
430 for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
431 #else
432 for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
433 #endif
434 g.nameOfExe = file_fullexename(g.argv[0]);
 
 
 
 
 
435 for(i=1; i<g.argc-1; i++){
436 z = g.argv[i];
437 if( z[0]!='-' ) continue;
438 z++;
439 if( z[0]=='-' ) z++;
440

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button