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.
Commit
ec02acfd095752419ce85bc2482dfdb6f02935597989c1491e3d2cffe639d0d7
Parent
491b986d0de38fb…
2 files changed
+8
-1
+1
-6
M
src/db.c
+8
-1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1635,19 +1635,26 @@ | ||
| 1635 | 1635 | ** connection. An error results in process abort. |
| 1636 | 1636 | */ |
| 1637 | 1637 | LOCAL sqlite3 *db_open(const char *zDbName){ |
| 1638 | 1638 | int rc; |
| 1639 | 1639 | sqlite3 *db; |
| 1640 | + Blob bNameCheck = BLOB_INITIALIZER; | |
| 1640 | 1641 | |
| 1641 | 1642 | 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 ){ | |
| 1643 | 1649 | extern int sqlite3_appendvfs_init( |
| 1644 | 1650 | sqlite3 *, char **, const sqlite3_api_routines * |
| 1645 | 1651 | ); |
| 1646 | 1652 | sqlite3_appendvfs_init(0,0,0); |
| 1647 | 1653 | g.zVfsName = "apndvfs"; |
| 1648 | 1654 | } |
| 1655 | + blob_zero(&bNameCheck); | |
| 1649 | 1656 | rc = sqlite3_open_v2( |
| 1650 | 1657 | zDbName, &db, |
| 1651 | 1658 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, |
| 1652 | 1659 | g.zVfsName |
| 1653 | 1660 | ); |
| 1654 | 1661 |
| --- 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 @@ | ||
| 432 | 432 | #if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE) |
| 433 | 433 | for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]); |
| 434 | 434 | #else |
| 435 | 435 | for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]); |
| 436 | 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 | |
| 437 | + g.nameOfExe = file_fullexename(g.argv[0]); | |
| 443 | 438 | for(i=1; i<g.argc-1; i++){ |
| 444 | 439 | z = g.argv[i]; |
| 445 | 440 | if( z[0]!='-' ) continue; |
| 446 | 441 | z++; |
| 447 | 442 | if( z[0]=='-' ) z++; |
| 448 | 443 |
| --- 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 |