Fossil SCM
Improved validation and checking when opening bundles.
Commit
f82dd1556b88950524000877960a672c9a907d35
Parent
9f63c8a3fe1ea68…
1 file changed
+34
-2
+34
-2
| --- src/bundle.c | ||
| +++ src/bundle.c | ||
| @@ -52,12 +52,44 @@ | ||
| 52 | 52 | static void bundle_attach_file( |
| 53 | 53 | const char *zFile, /* Name of the file that contains the bundle */ |
| 54 | 54 | const char *zBName, /* Attachment name */ |
| 55 | 55 | int doInit /* Initialize a new bundle, if true */ |
| 56 | 56 | ){ |
| 57 | - db_multi_exec("ATTACH %Q AS %Q;", zFile, zBName); | |
| 58 | - db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName); | |
| 57 | + int rc; | |
| 58 | + char *zErrMsg = 0; | |
| 59 | + char *zSql; | |
| 60 | + if( !doInit && file_size(zFile)<0 ){ | |
| 61 | + fossil_fatal("no such file: %s", zFile); | |
| 62 | + } | |
| 63 | + assert( g.db ); | |
| 64 | + zSql = sqlite3_mprintf("ATTACH %Q AS %Q", zFile, zBName); | |
| 65 | + if( zSql==0 ) fossil_fatal("out of memory"); | |
| 66 | + rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg); | |
| 67 | + sqlite3_free(zSql); | |
| 68 | + if( rc!=SQLITE_OK || zErrMsg ){ | |
| 69 | + if( zErrMsg==0 ) zErrMsg = sqlite3_errmsg(g.db); | |
| 70 | + fossil_fatal("not a valid bundle: %s", zFile); | |
| 71 | + } | |
| 72 | + if( doInit ){ | |
| 73 | + db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName); | |
| 74 | + }else{ | |
| 75 | + sqlite3_stmt *pStmt; | |
| 76 | + zSql = sqlite3_mprintf("SELECT bcname, bcvalue" | |
| 77 | + " FROM \"%w\".bconfig", zBName); | |
| 78 | + if( zSql==0 ) fossil_fatal("out of memory"); | |
| 79 | + rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, 0); | |
| 80 | + if( rc ) fossil_fatal("not a valid bundle: %s", zFile); | |
| 81 | + sqlite3_free(zSql); | |
| 82 | + sqlite3_finalize(pStmt); | |
| 83 | + zSql = sqlite3_mprintf("SELECT blobid, uuid, sz, delta, notes, data" | |
| 84 | + " FROM \"%w\".bblob", zBName); | |
| 85 | + if( zSql==0 ) fossil_fatal("out of memory"); | |
| 86 | + rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, 0); | |
| 87 | + if( rc ) fossil_fatal("not a valid bundle: %s", zFile); | |
| 88 | + sqlite3_free(zSql); | |
| 89 | + sqlite3_finalize(pStmt); | |
| 90 | + } | |
| 59 | 91 | } |
| 60 | 92 | |
| 61 | 93 | /* |
| 62 | 94 | ** fossil bundle ls BUNDLE ?OPTIONS? |
| 63 | 95 | ** |
| 64 | 96 |
| --- src/bundle.c | |
| +++ src/bundle.c | |
| @@ -52,12 +52,44 @@ | |
| 52 | static void bundle_attach_file( |
| 53 | const char *zFile, /* Name of the file that contains the bundle */ |
| 54 | const char *zBName, /* Attachment name */ |
| 55 | int doInit /* Initialize a new bundle, if true */ |
| 56 | ){ |
| 57 | db_multi_exec("ATTACH %Q AS %Q;", zFile, zBName); |
| 58 | db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName); |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | ** fossil bundle ls BUNDLE ?OPTIONS? |
| 63 | ** |
| 64 |
| --- src/bundle.c | |
| +++ src/bundle.c | |
| @@ -52,12 +52,44 @@ | |
| 52 | static void bundle_attach_file( |
| 53 | const char *zFile, /* Name of the file that contains the bundle */ |
| 54 | const char *zBName, /* Attachment name */ |
| 55 | int doInit /* Initialize a new bundle, if true */ |
| 56 | ){ |
| 57 | int rc; |
| 58 | char *zErrMsg = 0; |
| 59 | char *zSql; |
| 60 | if( !doInit && file_size(zFile)<0 ){ |
| 61 | fossil_fatal("no such file: %s", zFile); |
| 62 | } |
| 63 | assert( g.db ); |
| 64 | zSql = sqlite3_mprintf("ATTACH %Q AS %Q", zFile, zBName); |
| 65 | if( zSql==0 ) fossil_fatal("out of memory"); |
| 66 | rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg); |
| 67 | sqlite3_free(zSql); |
| 68 | if( rc!=SQLITE_OK || zErrMsg ){ |
| 69 | if( zErrMsg==0 ) zErrMsg = sqlite3_errmsg(g.db); |
| 70 | fossil_fatal("not a valid bundle: %s", zFile); |
| 71 | } |
| 72 | if( doInit ){ |
| 73 | db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName); |
| 74 | }else{ |
| 75 | sqlite3_stmt *pStmt; |
| 76 | zSql = sqlite3_mprintf("SELECT bcname, bcvalue" |
| 77 | " FROM \"%w\".bconfig", zBName); |
| 78 | if( zSql==0 ) fossil_fatal("out of memory"); |
| 79 | rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, 0); |
| 80 | if( rc ) fossil_fatal("not a valid bundle: %s", zFile); |
| 81 | sqlite3_free(zSql); |
| 82 | sqlite3_finalize(pStmt); |
| 83 | zSql = sqlite3_mprintf("SELECT blobid, uuid, sz, delta, notes, data" |
| 84 | " FROM \"%w\".bblob", zBName); |
| 85 | if( zSql==0 ) fossil_fatal("out of memory"); |
| 86 | rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, 0); |
| 87 | if( rc ) fossil_fatal("not a valid bundle: %s", zFile); |
| 88 | sqlite3_free(zSql); |
| 89 | sqlite3_finalize(pStmt); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | ** fossil bundle ls BUNDLE ?OPTIONS? |
| 95 | ** |
| 96 |