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].
Commit
ab7ad2348c1a357c04d19c9bbaf57aba3f40c7bade3034c5633d793b0397017f
Parent
adfc1a6b601d274…
3 files changed
+8
-1
+8
-1
+1
-9
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 |
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
-9
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -420,28 +420,20 @@ | ||
| 420 | 420 | unsigned int nArg; /* Number of new arguments */ |
| 421 | 421 | char *z; /* General use string pointer */ |
| 422 | 422 | char **newArgv; /* New expanded g.argv under construction */ |
| 423 | 423 | const char *zFileName; /* input file name */ |
| 424 | 424 | FILE *inFile; /* input FILE */ |
| 425 | -#if defined(_WIN32) | |
| 426 | - wchar_t buf[MAX_PATH]; | |
| 427 | -#endif | |
| 428 | 425 | |
| 429 | 426 | g.argc = argc; |
| 430 | 427 | g.argv = argv; |
| 431 | 428 | sqlite3_initialize(); |
| 432 | 429 | #if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE) |
| 433 | 430 | for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]); |
| 434 | 431 | #else |
| 435 | 432 | for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]); |
| 436 | 433 | #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]); | |
| 443 | 435 | for(i=1; i<g.argc-1; i++){ |
| 444 | 436 | z = g.argv[i]; |
| 445 | 437 | if( z[0]!='-' ) continue; |
| 446 | 438 | z++; |
| 447 | 439 | if( z[0]=='-' ) z++; |
| 448 | 440 |
| --- 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 |