Fossil SCM

Resolve the bug revealed in [forum:16880a28aad1a868 | forum post 16880a28aad1a868] in which the db_open() appendvfs check can misinteract with g.nameOfExe. This is in a branch until a Windows user can confirm that the g.nameOfExe change in main.c behaves as desired on Windows. This was a collaborative bug fix via /chat, not my own.

stephan 2022-02-28 21:30 trunk
Commit ec02acfd095752419ce85bc2482dfdb6f02935597989c1491e3d2cffe639d0d7
2 files changed +8 -1 +1 -6
+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 -6
--- src/main.c
+++ src/main.c
@@ -432,16 +432,11 @@
432432
#if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
433433
for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
434434
#else
435435
for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
436436
#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
437
+ g.nameOfExe = file_fullexename(g.argv[0]);
443438
for(i=1; i<g.argc-1; i++){
444439
z = g.argv[i];
445440
if( z[0]!='-' ) continue;
446441
z++;
447442
if( z[0]=='-' ) z++;
448443
--- src/main.c
+++ src/main.c
@@ -432,16 +432,11 @@
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
@@ -432,16 +432,11 @@
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 g.nameOfExe = file_fullexename(g.argv[0]);
 
 
 
 
 
438 for(i=1; i<g.argc-1; i++){
439 z = g.argv[i];
440 if( z[0]!='-' ) continue;
441 z++;
442 if( z[0]=='-' ) z++;
443

Keyboard Shortcuts

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