Fossil SCM

Improved validation and checking when opening bundles.

drh 2014-12-02 13:15 UTC DBP-workflow
Commit f82dd1556b88950524000877960a672c9a907d35
1 file changed +34 -2
+34 -2
--- src/bundle.c
+++ src/bundle.c
@@ -52,12 +52,44 @@
5252
static void bundle_attach_file(
5353
const char *zFile, /* Name of the file that contains the bundle */
5454
const char *zBName, /* Attachment name */
5555
int doInit /* Initialize a new bundle, if true */
5656
){
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
+ }
5991
}
6092
6193
/*
6294
** fossil bundle ls BUNDLE ?OPTIONS?
6395
**
6496
--- 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

Keyboard Shortcuts

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