Fossil SCM

Merge small-fixes-2 into trunk. This brings twenty fixes, among them purge undo and scrub --private, bounds checks in the svn importer, the If-Modified-Since and SCGI parsers, TH1 arithmetic, and the sync client and server.

dmestas 2026-11-18 18:59 UTC trunk merge
Commit 8b0dbb2f3e5fba184080fa442e1f78c6b2a60b5be54b217a0b191ec135988ca1
+4 -2
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,12 @@
13351335
nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
13361336
if( nWrote>=0 ) return nWrote;
13371337
fflush(stdout);
13381338
_setmode(_fileno(stdout), _O_BINARY);
13391339
#endif
1340
- nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout);
1340
+ nWrote = blob_size(pBlob)>0
1341
+ ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout) : 0;
13411342
#if defined(_WIN32)
13421343
fflush(stdout);
13431344
_setmode(_fileno(stdout), _O_TEXT);
13441345
#endif
13451346
}else{
@@ -1356,11 +1357,12 @@
13561357
fossil_fatal_recursive("unable to open file \"%s\" for writing",
13571358
zFilename);
13581359
return 0;
13591360
}
13601361
blob_is_init(pBlob);
1361
- nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
1362
+ nWrote = blob_size(pBlob)>0
1363
+ ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out) : 0;
13621364
fclose(out);
13631365
if( nWrote!=(int)blob_size(pBlob) ){
13641366
fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
13651367
blob_size(pBlob), zFilename);
13661368
}
13671369
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,12 @@
1335 nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
1336 if( nWrote>=0 ) return nWrote;
1337 fflush(stdout);
1338 _setmode(_fileno(stdout), _O_BINARY);
1339 #endif
1340 nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout);
 
1341 #if defined(_WIN32)
1342 fflush(stdout);
1343 _setmode(_fileno(stdout), _O_TEXT);
1344 #endif
1345 }else{
@@ -1356,11 +1357,12 @@
1356 fossil_fatal_recursive("unable to open file \"%s\" for writing",
1357 zFilename);
1358 return 0;
1359 }
1360 blob_is_init(pBlob);
1361 nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
 
1362 fclose(out);
1363 if( nWrote!=(int)blob_size(pBlob) ){
1364 fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
1365 blob_size(pBlob), zFilename);
1366 }
1367
--- src/blob.c
+++ src/blob.c
@@ -1335,11 +1335,12 @@
1335 nWrote = fossil_utf8_to_console(blob_buffer(pBlob), blob_size(pBlob), 0);
1336 if( nWrote>=0 ) return nWrote;
1337 fflush(stdout);
1338 _setmode(_fileno(stdout), _O_BINARY);
1339 #endif
1340 nWrote = blob_size(pBlob)>0
1341 ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), stdout) : 0;
1342 #if defined(_WIN32)
1343 fflush(stdout);
1344 _setmode(_fileno(stdout), _O_TEXT);
1345 #endif
1346 }else{
@@ -1356,11 +1357,12 @@
1357 fossil_fatal_recursive("unable to open file \"%s\" for writing",
1358 zFilename);
1359 return 0;
1360 }
1361 blob_is_init(pBlob);
1362 nWrote = blob_size(pBlob)>0
1363 ? fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out) : 0;
1364 fclose(out);
1365 if( nWrote!=(int)blob_size(pBlob) ){
1366 fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
1367 blob_size(pBlob), zFilename);
1368 }
1369
+5
--- src/cgi.c
+++ src/cgi.c
@@ -2540,10 +2540,11 @@
25402540
int nRead;
25412541
int c, n, m;
25422542
25432543
assert( !g.httpUseSSL );
25442544
while( (c = fgetc(g.httpIn))!=EOF && fossil_isdigit((char)c) ){
2545
+ if( nHdr>=100000000 ) malformed_request("SCGI header too long");
25452546
nHdr = nHdr*10 + (char)c - '0';
25462547
}
25472548
if( nHdr<16 ) malformed_request("SCGI header too short");
25482549
zToFree = zHdr = fossil_malloc(nHdr);
25492550
nRead = (int)fread(zHdr, 1, nHdr, g.httpIn);
@@ -2982,10 +2983,14 @@
29822983
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
29832984
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
29842985
if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
29852986
&mday, zMonth, &year, &hour, &min, &sec)){
29862987
if( year > 1900 ) year -= 1900;
2988
+ if( year<70 || year>8099 || mday<1 || mday>31
2989
+ || hour<0 || hour>23 || min<0 || min>59 || sec<0 || sec>60 ){
2990
+ return 0;
2991
+ }
29872992
for(mon=0; azMonths[mon]; mon++){
29882993
if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
29892994
int nDay;
29902995
int isLeapYr;
29912996
static int priorDays[] =
29922997
--- src/cgi.c
+++ src/cgi.c
@@ -2540,10 +2540,11 @@
2540 int nRead;
2541 int c, n, m;
2542
2543 assert( !g.httpUseSSL );
2544 while( (c = fgetc(g.httpIn))!=EOF && fossil_isdigit((char)c) ){
 
2545 nHdr = nHdr*10 + (char)c - '0';
2546 }
2547 if( nHdr<16 ) malformed_request("SCGI header too short");
2548 zToFree = zHdr = fossil_malloc(nHdr);
2549 nRead = (int)fread(zHdr, 1, nHdr, g.httpIn);
@@ -2982,10 +2983,14 @@
2982 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2983 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
2984 if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
2985 &mday, zMonth, &year, &hour, &min, &sec)){
2986 if( year > 1900 ) year -= 1900;
 
 
 
 
2987 for(mon=0; azMonths[mon]; mon++){
2988 if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
2989 int nDay;
2990 int isLeapYr;
2991 static int priorDays[] =
2992
--- src/cgi.c
+++ src/cgi.c
@@ -2540,10 +2540,11 @@
2540 int nRead;
2541 int c, n, m;
2542
2543 assert( !g.httpUseSSL );
2544 while( (c = fgetc(g.httpIn))!=EOF && fossil_isdigit((char)c) ){
2545 if( nHdr>=100000000 ) malformed_request("SCGI header too long");
2546 nHdr = nHdr*10 + (char)c - '0';
2547 }
2548 if( nHdr<16 ) malformed_request("SCGI header too short");
2549 zToFree = zHdr = fossil_malloc(nHdr);
2550 nRead = (int)fread(zHdr, 1, nHdr, g.httpIn);
@@ -2982,10 +2983,14 @@
2983 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2984 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
2985 if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
2986 &mday, zMonth, &year, &hour, &min, &sec)){
2987 if( year > 1900 ) year -= 1900;
2988 if( year<70 || year>8099 || mday<1 || mday>31
2989 || hour<0 || hour>23 || min<0 || min>59 || sec<0 || sec>60 ){
2990 return 0;
2991 }
2992 for(mon=0; azMonths[mon]; mon++){
2993 if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
2994 int nDay;
2995 int isLeapYr;
2996 static int priorDays[] =
2997
+60 -25
--- src/import.c
+++ src/import.c
@@ -105,11 +105,11 @@
105105
for(i=0; i<gg.nFile; i++){
106106
fossil_free(gg.aFile[i].zName);
107107
fossil_free(gg.aFile[i].zUuid);
108108
fossil_free(gg.aFile[i].zPrior);
109109
}
110
- memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0]));
110
+ if( gg.nFile ) memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0]));
111111
gg.nFile = 0;
112112
if( freeAll ){
113113
fossil_free(gg.zPrevBranch);
114114
fossil_free(gg.zPrevCheckin);
115115
fossil_free(gg.azMerge);
@@ -265,11 +265,11 @@
265265
char *aTCard[4]; /* Array of T cards for manifest */
266266
int nTCard = 0; /* Entries used in aTCard[] */
267267
Blob record, cksum;
268268
269269
import_prior_files();
270
- qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
270
+ if( gg.nFile ) qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
271271
blob_zero(&record);
272272
blob_appendf(&record, "C %F\n", gg.zComment);
273273
blob_appendf(&record, "D %s\n", gg.zDate);
274274
if( !g.fQuiet ){
275275
fossil_print("%.10s\r", gg.zDate);
@@ -1224,72 +1224,107 @@
12241224
}
12251225
db_reset(&getChanges);
12261226
db_finalize(&setRid);
12271227
}
12281228
1229
-static u64 svn_get_varint(const char **pz){
1229
+static u64 svn_get_varint(const char **pz, const char *zEnd){
12301230
unsigned int v = 0;
12311231
do{
1232
+ if( *pz>=zEnd ) fossil_fatal("Invalid svndiff0 format");
12321233
v = (v<<7) | ((*pz)[0]&0x7f);
12331234
}while( (*pz)++[0]&0x80 );
12341235
return v;
12351236
}
12361237
1238
+/*
1239
+** Apply the svndiff0 delta in pDiff to pSrc and write the result into
1240
+** pOut. Every offset and length is checked against the buffer it names
1241
+** before it is used.
1242
+*/
12371243
static void svn_apply_svndiff(Blob *pDiff, Blob *pSrc, Blob *pOut){
12381244
const char *zDiff = blob_buffer(pDiff);
1245
+ const char *zEnd = zDiff + blob_size(pDiff);
1246
+ u64 nSrc = blob_size(pSrc);
12391247
char *zOut;
12401248
if( blob_size(pDiff)<4 || memcmp(zDiff, "SVN", 4)!=0 ){
12411249
fossil_fatal("Invalid svndiff0 format");
12421250
}
12431251
zDiff += 4;
12441252
blob_zero(pOut);
1245
- while( zDiff<(blob_buffer(pDiff)+blob_size(pDiff)) ){
1246
- u64 lenOut, lenInst, lenData, lenOld;
1253
+ while( zDiff<zEnd ){
1254
+ u64 lenOut, lenInst, lenData, lenOld, lenLeft;
12471255
const char *zInst;
12481256
const char *zData;
1257
+ const char *zDataEnd;
12491258
1250
- u64 offSrc = svn_get_varint(&zDiff);
1251
- /*lenSrc =*/ svn_get_varint(&zDiff);
1252
- lenOut = svn_get_varint(&zDiff);
1253
- lenInst = svn_get_varint(&zDiff);
1254
- lenData = svn_get_varint(&zDiff);
1259
+ u64 offSrc = svn_get_varint(&zDiff, zEnd);
1260
+ /*lenSrc =*/ svn_get_varint(&zDiff, zEnd);
1261
+ lenOut = svn_get_varint(&zDiff, zEnd);
1262
+ lenInst = svn_get_varint(&zDiff, zEnd);
1263
+ lenData = svn_get_varint(&zDiff, zEnd);
1264
+ if( lenInst>(u64)(zEnd-zDiff) || lenData>(u64)(zEnd-zDiff)-lenInst ){
1265
+ fossil_fatal("Invalid svndiff0 format");
1266
+ }
12551267
zInst = zDiff;
12561268
zData = zInst+lenInst;
1269
+ zDataEnd = zData+lenData;
12571270
lenOld = blob_size(pOut);
12581271
blob_resize(pOut, lenOut+lenOld);
12591272
zOut = blob_buffer(pOut)+lenOld;
1273
+ lenLeft = lenOut;
12601274
while( zDiff<zInst+lenInst ){
12611275
u64 lenCpy = (*zDiff)&0x3f;
1276
+ u64 off = 0;
12621277
const char *zCpy;
1263
- switch( (*zDiff)&0xC0 ){
1278
+ int op = (*zDiff)&0xC0;
1279
+ zDiff++;
1280
+ if( lenCpy==0 ){
1281
+ lenCpy = svn_get_varint(&zDiff, zInst+lenInst);
1282
+ }
1283
+ if( op!=0x80 ){
1284
+ off = svn_get_varint(&zDiff, zInst+lenInst);
1285
+ }
1286
+ if( lenCpy>lenLeft ){
1287
+ fossil_fatal("Invalid svndiff0 format");
1288
+ }
1289
+ switch( op ){
12641290
case 0x00:
1265
- if( 0==blob_size(pSrc) ){
1291
+ if( 0==nSrc ){
12661292
/* https://fossil-scm.org/forum/forumpost/15d4b242bda2a108 */
12671293
fossil_fatal("Don't know how to handle NULL input. "
12681294
"Tip: do not use the --incremental flag "
12691295
"in the svn dump command.");
12701296
}
1271
- zCpy = blob_buffer(pSrc)+offSrc;
1297
+ if( offSrc>nSrc || off>nSrc-offSrc || lenCpy>nSrc-offSrc-off ){
1298
+ fossil_fatal("Invalid svndiff0 format");
1299
+ }
1300
+ zCpy = blob_buffer(pSrc)+offSrc+off;
1301
+ break;
1302
+ case 0x40:
1303
+ if( lenCpy>0 && off>=(u64)(zOut-blob_buffer(pOut)) ){
1304
+ fossil_fatal("Invalid svndiff0 format");
1305
+ }
1306
+ zCpy = blob_buffer(pOut)+off;
12721307
break;
1273
- case 0x40: zCpy = blob_buffer(pOut); break;
1274
- case 0x80: zCpy = zData; break;
1308
+ case 0x80:
1309
+ if( lenCpy>(u64)(zDataEnd-zData) ){
1310
+ fossil_fatal("Invalid svndiff0 format");
1311
+ }
1312
+ zCpy = zData;
1313
+ zData += lenCpy;
1314
+ break;
12751315
default: fossil_fatal("Invalid svndiff0 instruction");
12761316
}
1277
- zDiff++;
1278
- if( lenCpy==0 ){
1279
- lenCpy = svn_get_varint(&zDiff);
1280
- }
1281
- if( zCpy!=zData ){
1282
- zCpy += svn_get_varint(&zDiff);
1283
- }else{
1284
- zData += lenCpy;
1285
- }
1317
+ lenLeft -= lenCpy;
12861318
while( lenCpy-- > 0 ){
12871319
*zOut++ = *zCpy++;
12881320
}
12891321
}
1290
- zDiff += lenData;
1322
+ if( lenLeft!=0 ){
1323
+ fossil_fatal("Invalid svndiff0 format");
1324
+ }
1325
+ zDiff = zDataEnd;
12911326
}
12921327
}
12931328
12941329
/*
12951330
** Extract the branch or tag that the given path is on. Return the branch ID.
12961331
--- src/import.c
+++ src/import.c
@@ -105,11 +105,11 @@
105 for(i=0; i<gg.nFile; i++){
106 fossil_free(gg.aFile[i].zName);
107 fossil_free(gg.aFile[i].zUuid);
108 fossil_free(gg.aFile[i].zPrior);
109 }
110 memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0]));
111 gg.nFile = 0;
112 if( freeAll ){
113 fossil_free(gg.zPrevBranch);
114 fossil_free(gg.zPrevCheckin);
115 fossil_free(gg.azMerge);
@@ -265,11 +265,11 @@
265 char *aTCard[4]; /* Array of T cards for manifest */
266 int nTCard = 0; /* Entries used in aTCard[] */
267 Blob record, cksum;
268
269 import_prior_files();
270 qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
271 blob_zero(&record);
272 blob_appendf(&record, "C %F\n", gg.zComment);
273 blob_appendf(&record, "D %s\n", gg.zDate);
274 if( !g.fQuiet ){
275 fossil_print("%.10s\r", gg.zDate);
@@ -1224,72 +1224,107 @@
1224 }
1225 db_reset(&getChanges);
1226 db_finalize(&setRid);
1227 }
1228
1229 static u64 svn_get_varint(const char **pz){
1230 unsigned int v = 0;
1231 do{
 
1232 v = (v<<7) | ((*pz)[0]&0x7f);
1233 }while( (*pz)++[0]&0x80 );
1234 return v;
1235 }
1236
 
 
 
 
 
1237 static void svn_apply_svndiff(Blob *pDiff, Blob *pSrc, Blob *pOut){
1238 const char *zDiff = blob_buffer(pDiff);
 
 
1239 char *zOut;
1240 if( blob_size(pDiff)<4 || memcmp(zDiff, "SVN", 4)!=0 ){
1241 fossil_fatal("Invalid svndiff0 format");
1242 }
1243 zDiff += 4;
1244 blob_zero(pOut);
1245 while( zDiff<(blob_buffer(pDiff)+blob_size(pDiff)) ){
1246 u64 lenOut, lenInst, lenData, lenOld;
1247 const char *zInst;
1248 const char *zData;
 
1249
1250 u64 offSrc = svn_get_varint(&zDiff);
1251 /*lenSrc =*/ svn_get_varint(&zDiff);
1252 lenOut = svn_get_varint(&zDiff);
1253 lenInst = svn_get_varint(&zDiff);
1254 lenData = svn_get_varint(&zDiff);
 
 
 
1255 zInst = zDiff;
1256 zData = zInst+lenInst;
 
1257 lenOld = blob_size(pOut);
1258 blob_resize(pOut, lenOut+lenOld);
1259 zOut = blob_buffer(pOut)+lenOld;
 
1260 while( zDiff<zInst+lenInst ){
1261 u64 lenCpy = (*zDiff)&0x3f;
 
1262 const char *zCpy;
1263 switch( (*zDiff)&0xC0 ){
 
 
 
 
 
 
 
 
 
 
 
1264 case 0x00:
1265 if( 0==blob_size(pSrc) ){
1266 /* https://fossil-scm.org/forum/forumpost/15d4b242bda2a108 */
1267 fossil_fatal("Don't know how to handle NULL input. "
1268 "Tip: do not use the --incremental flag "
1269 "in the svn dump command.");
1270 }
1271 zCpy = blob_buffer(pSrc)+offSrc;
 
 
 
 
 
 
 
 
 
1272 break;
1273 case 0x40: zCpy = blob_buffer(pOut); break;
1274 case 0x80: zCpy = zData; break;
 
 
 
 
 
1275 default: fossil_fatal("Invalid svndiff0 instruction");
1276 }
1277 zDiff++;
1278 if( lenCpy==0 ){
1279 lenCpy = svn_get_varint(&zDiff);
1280 }
1281 if( zCpy!=zData ){
1282 zCpy += svn_get_varint(&zDiff);
1283 }else{
1284 zData += lenCpy;
1285 }
1286 while( lenCpy-- > 0 ){
1287 *zOut++ = *zCpy++;
1288 }
1289 }
1290 zDiff += lenData;
 
 
 
1291 }
1292 }
1293
1294 /*
1295 ** Extract the branch or tag that the given path is on. Return the branch ID.
1296
--- src/import.c
+++ src/import.c
@@ -105,11 +105,11 @@
105 for(i=0; i<gg.nFile; i++){
106 fossil_free(gg.aFile[i].zName);
107 fossil_free(gg.aFile[i].zUuid);
108 fossil_free(gg.aFile[i].zPrior);
109 }
110 if( gg.nFile ) memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0]));
111 gg.nFile = 0;
112 if( freeAll ){
113 fossil_free(gg.zPrevBranch);
114 fossil_free(gg.zPrevCheckin);
115 fossil_free(gg.azMerge);
@@ -265,11 +265,11 @@
265 char *aTCard[4]; /* Array of T cards for manifest */
266 int nTCard = 0; /* Entries used in aTCard[] */
267 Blob record, cksum;
268
269 import_prior_files();
270 if( gg.nFile ) qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
271 blob_zero(&record);
272 blob_appendf(&record, "C %F\n", gg.zComment);
273 blob_appendf(&record, "D %s\n", gg.zDate);
274 if( !g.fQuiet ){
275 fossil_print("%.10s\r", gg.zDate);
@@ -1224,72 +1224,107 @@
1224 }
1225 db_reset(&getChanges);
1226 db_finalize(&setRid);
1227 }
1228
1229 static u64 svn_get_varint(const char **pz, const char *zEnd){
1230 unsigned int v = 0;
1231 do{
1232 if( *pz>=zEnd ) fossil_fatal("Invalid svndiff0 format");
1233 v = (v<<7) | ((*pz)[0]&0x7f);
1234 }while( (*pz)++[0]&0x80 );
1235 return v;
1236 }
1237
1238 /*
1239 ** Apply the svndiff0 delta in pDiff to pSrc and write the result into
1240 ** pOut. Every offset and length is checked against the buffer it names
1241 ** before it is used.
1242 */
1243 static void svn_apply_svndiff(Blob *pDiff, Blob *pSrc, Blob *pOut){
1244 const char *zDiff = blob_buffer(pDiff);
1245 const char *zEnd = zDiff + blob_size(pDiff);
1246 u64 nSrc = blob_size(pSrc);
1247 char *zOut;
1248 if( blob_size(pDiff)<4 || memcmp(zDiff, "SVN", 4)!=0 ){
1249 fossil_fatal("Invalid svndiff0 format");
1250 }
1251 zDiff += 4;
1252 blob_zero(pOut);
1253 while( zDiff<zEnd ){
1254 u64 lenOut, lenInst, lenData, lenOld, lenLeft;
1255 const char *zInst;
1256 const char *zData;
1257 const char *zDataEnd;
1258
1259 u64 offSrc = svn_get_varint(&zDiff, zEnd);
1260 /*lenSrc =*/ svn_get_varint(&zDiff, zEnd);
1261 lenOut = svn_get_varint(&zDiff, zEnd);
1262 lenInst = svn_get_varint(&zDiff, zEnd);
1263 lenData = svn_get_varint(&zDiff, zEnd);
1264 if( lenInst>(u64)(zEnd-zDiff) || lenData>(u64)(zEnd-zDiff)-lenInst ){
1265 fossil_fatal("Invalid svndiff0 format");
1266 }
1267 zInst = zDiff;
1268 zData = zInst+lenInst;
1269 zDataEnd = zData+lenData;
1270 lenOld = blob_size(pOut);
1271 blob_resize(pOut, lenOut+lenOld);
1272 zOut = blob_buffer(pOut)+lenOld;
1273 lenLeft = lenOut;
1274 while( zDiff<zInst+lenInst ){
1275 u64 lenCpy = (*zDiff)&0x3f;
1276 u64 off = 0;
1277 const char *zCpy;
1278 int op = (*zDiff)&0xC0;
1279 zDiff++;
1280 if( lenCpy==0 ){
1281 lenCpy = svn_get_varint(&zDiff, zInst+lenInst);
1282 }
1283 if( op!=0x80 ){
1284 off = svn_get_varint(&zDiff, zInst+lenInst);
1285 }
1286 if( lenCpy>lenLeft ){
1287 fossil_fatal("Invalid svndiff0 format");
1288 }
1289 switch( op ){
1290 case 0x00:
1291 if( 0==nSrc ){
1292 /* https://fossil-scm.org/forum/forumpost/15d4b242bda2a108 */
1293 fossil_fatal("Don't know how to handle NULL input. "
1294 "Tip: do not use the --incremental flag "
1295 "in the svn dump command.");
1296 }
1297 if( offSrc>nSrc || off>nSrc-offSrc || lenCpy>nSrc-offSrc-off ){
1298 fossil_fatal("Invalid svndiff0 format");
1299 }
1300 zCpy = blob_buffer(pSrc)+offSrc+off;
1301 break;
1302 case 0x40:
1303 if( lenCpy>0 && off>=(u64)(zOut-blob_buffer(pOut)) ){
1304 fossil_fatal("Invalid svndiff0 format");
1305 }
1306 zCpy = blob_buffer(pOut)+off;
1307 break;
1308 case 0x80:
1309 if( lenCpy>(u64)(zDataEnd-zData) ){
1310 fossil_fatal("Invalid svndiff0 format");
1311 }
1312 zCpy = zData;
1313 zData += lenCpy;
1314 break;
1315 default: fossil_fatal("Invalid svndiff0 instruction");
1316 }
1317 lenLeft -= lenCpy;
 
 
 
 
 
 
 
 
1318 while( lenCpy-- > 0 ){
1319 *zOut++ = *zCpy++;
1320 }
1321 }
1322 if( lenLeft!=0 ){
1323 fossil_fatal("Invalid svndiff0 format");
1324 }
1325 zDiff = zDataEnd;
1326 }
1327 }
1328
1329 /*
1330 ** Extract the branch or tag that the given path is on. Return the branch ID.
1331
+4 -5
--- src/manifest.c
+++ src/manifest.c
@@ -2661,11 +2661,11 @@
26612661
"Add attachment [/artifact/%!S|%h] to [/artifact/%!S|%h]",
26622662
p->zAttachSrc, p->zAttachName,
26632663
p->zAttachTarget, p->zAttachTarget);
26642664
}else{
26652665
zComment = mprintf("Delete attachment \"%h\" from "
2666
- "[/artifact/%!S|%h",
2666
+ "[/artifact/%!S|%h]",
26672667
p->zAttachName, p->zAttachTarget,
26682668
p->zAttachTarget);
26692669
}
26702670
break;
26712671
case CFTYPE_WIKI:
@@ -2687,14 +2687,13 @@
26872687
"Add attachment [/artifact/%!S|%h] to tech note "
26882688
"[/technote/%!S|%S]",
26892689
p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget);
26902690
}else{
26912691
zComment = mprintf(
2692
- "Delete attachment \"/artifact/%!S|%h\" from"
2692
+ "Delete attachment \"%h\" from"
26932693
" tech note [/technote/%!S|%S]",
2694
- p->zAttachName, p->zAttachName,
2695
- p->zAttachTarget,p->zAttachTarget);
2694
+ p->zAttachName, p->zAttachTarget, p->zAttachTarget);
26962695
}
26972696
break;
26982697
case CFTYPE_TICKET:
26992698
attachToType = 't';
27002699
if( isAdd ){
@@ -2867,11 +2866,11 @@
28672866
);
28682867
/*
28692868
** If this edit is the most recent, then make it the title for
28702869
** all other entries for the same thread
28712870
*/
2872
- if( !db_exists("SELECT 1 FROM forumpost WHERE froot=%d AND firt=0"
2871
+ if( !db_exists("SELECT 1 FROM forumpost WHERE froot=%d AND firt IS NULL"
28732872
" AND fpid!=%d AND fmtime>%.17g", froot, rid, p->rDate)
28742873
){
28752874
/* This entry establishes a new title for all entries on the thread */
28762875
db_multi_exec(
28772876
"UPDATE event"
28782877
--- src/manifest.c
+++ src/manifest.c
@@ -2661,11 +2661,11 @@
2661 "Add attachment [/artifact/%!S|%h] to [/artifact/%!S|%h]",
2662 p->zAttachSrc, p->zAttachName,
2663 p->zAttachTarget, p->zAttachTarget);
2664 }else{
2665 zComment = mprintf("Delete attachment \"%h\" from "
2666 "[/artifact/%!S|%h",
2667 p->zAttachName, p->zAttachTarget,
2668 p->zAttachTarget);
2669 }
2670 break;
2671 case CFTYPE_WIKI:
@@ -2687,14 +2687,13 @@
2687 "Add attachment [/artifact/%!S|%h] to tech note "
2688 "[/technote/%!S|%S]",
2689 p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget);
2690 }else{
2691 zComment = mprintf(
2692 "Delete attachment \"/artifact/%!S|%h\" from"
2693 " tech note [/technote/%!S|%S]",
2694 p->zAttachName, p->zAttachName,
2695 p->zAttachTarget,p->zAttachTarget);
2696 }
2697 break;
2698 case CFTYPE_TICKET:
2699 attachToType = 't';
2700 if( isAdd ){
@@ -2867,11 +2866,11 @@
2867 );
2868 /*
2869 ** If this edit is the most recent, then make it the title for
2870 ** all other entries for the same thread
2871 */
2872 if( !db_exists("SELECT 1 FROM forumpost WHERE froot=%d AND firt=0"
2873 " AND fpid!=%d AND fmtime>%.17g", froot, rid, p->rDate)
2874 ){
2875 /* This entry establishes a new title for all entries on the thread */
2876 db_multi_exec(
2877 "UPDATE event"
2878
--- src/manifest.c
+++ src/manifest.c
@@ -2661,11 +2661,11 @@
2661 "Add attachment [/artifact/%!S|%h] to [/artifact/%!S|%h]",
2662 p->zAttachSrc, p->zAttachName,
2663 p->zAttachTarget, p->zAttachTarget);
2664 }else{
2665 zComment = mprintf("Delete attachment \"%h\" from "
2666 "[/artifact/%!S|%h]",
2667 p->zAttachName, p->zAttachTarget,
2668 p->zAttachTarget);
2669 }
2670 break;
2671 case CFTYPE_WIKI:
@@ -2687,14 +2687,13 @@
2687 "Add attachment [/artifact/%!S|%h] to tech note "
2688 "[/technote/%!S|%S]",
2689 p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget);
2690 }else{
2691 zComment = mprintf(
2692 "Delete attachment \"%h\" from"
2693 " tech note [/technote/%!S|%S]",
2694 p->zAttachName, p->zAttachTarget, p->zAttachTarget);
 
2695 }
2696 break;
2697 case CFTYPE_TICKET:
2698 attachToType = 't';
2699 if( isAdd ){
@@ -2867,11 +2866,11 @@
2866 );
2867 /*
2868 ** If this edit is the most recent, then make it the title for
2869 ** all other entries for the same thread
2870 */
2871 if( !db_exists("SELECT 1 FROM forumpost WHERE froot=%d AND firt IS NULL"
2872 " AND fpid!=%d AND fmtime>%.17g", froot, rid, p->rDate)
2873 ){
2874 /* This entry establishes a new title for all entries on the thread */
2875 db_multi_exec(
2876 "UPDATE event"
2877
+98 -5
--- src/purge.c
+++ src/purge.c
@@ -401,19 +401,19 @@
401401
fossil_fatal("delta loop while uncompressing purged artifacts");
402402
}
403403
bag_insert(&busy, iSrc);
404404
}
405405
db_prepare(&q,
406
- "SELECT uuid, data, isPrivate, ix.piid"
406
+ "SELECT uuid, data, isPrivate, ix.piid, orid"
407407
" FROM ix, purgeitem"
408408
" WHERE ix.srcid=%d"
409409
" AND ix.piid=purgeitem.piid;",
410410
iSrc
411411
);
412412
while( db_step(&q)==SQLITE_ROW ){
413413
Blob h1, c1, c2;
414
- int isPriv, rid;
414
+ int isPriv, rid, orid;
415415
blob_zero(&h1);
416416
db_column_blob(&q, 0, &h1);
417417
blob_zero(&c1);
418418
db_column_blob(&q, 1, &c1);
419419
blob_uncompress(&c1, &c1);
@@ -426,10 +426,26 @@
426426
}
427427
if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){
428428
fossil_fatal("incorrect hash on %b", &h1);
429429
}
430430
isPriv = db_column_int(&q, 2);
431
+ orid = db_column_int(&q, 4);
432
+ if( orid>0
433
+ && !db_exists("SELECT 1 FROM blob WHERE rid=%d OR uuid=%Q",
434
+ orid, blob_str(&h1))
435
+ ){
436
+ /* Restore it under its old record number, which links still name */
437
+ db_multi_exec(
438
+ "INSERT INTO blob(rid,rcvid,size,uuid,content)"
439
+ " VALUES(%d,0,-1,%Q,NULL);"
440
+ "INSERT INTO phantom VALUES(%d);",
441
+ orid, blob_str(&h1), orid
442
+ );
443
+ if( !isPriv ){
444
+ db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d)", orid);
445
+ }
446
+ }
431447
rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
432448
if( rid==0 ){
433449
fossil_fatal("%s", g.zErrMsg);
434450
}else{
435451
if( !isPriv ) content_make_public(rid);
@@ -440,10 +456,47 @@
440456
blob_reset(&c2);
441457
}
442458
db_finalize(&q);
443459
if( iSrc>0 ) bag_remove(&busy, iSrc);
444460
}
461
+
462
+/*
463
+** Remove from the graveyard every artifact that was private when it was
464
+** purged, and any purge event left empty, so that "fossil scrub" leaves
465
+** no private content behind. An item that stays, but is stored as a
466
+** delta from one that goes, is stored whole first.
467
+*/
468
+void purge_drop_private_items(void){
469
+ Stmt q;
470
+ if( !db_table_exists("repository","purgeitem") ) return;
471
+ db_multi_exec(
472
+ "CREATE TEMP TABLE pwhole AS"
473
+ " SELECT piid FROM purgeitem WHERE NOT isPrivate"
474
+ " AND srcid IN (SELECT piid FROM purgeitem WHERE isPrivate)"
475
+ );
476
+ db_prepare(&q, "SELECT piid FROM pwhole");
477
+ while( db_step(&q)==SQLITE_ROW ){
478
+ int piid = db_column_int(&q, 0);
479
+ Blob content, cmpr;
480
+ Stmt u;
481
+ purge_extract_item(piid, &content);
482
+ blob_compress(&content, &cmpr);
483
+ db_prepare(&u, "UPDATE purgeitem SET srcid=NULL, data=:data"
484
+ " WHERE piid=%d", piid);
485
+ db_bind_blob(&u, ":data", &cmpr);
486
+ db_exec(&u);
487
+ db_finalize(&u);
488
+ blob_reset(&content);
489
+ blob_reset(&cmpr);
490
+ }
491
+ db_finalize(&q);
492
+ db_multi_exec(
493
+ "DROP TABLE pwhole;"
494
+ "DELETE FROM purgeitem WHERE isPrivate;"
495
+ "DELETE FROM purgeevent WHERE peid NOT IN (SELECT peid FROM purgeitem);"
496
+ );
497
+}
445498
446499
/*
447500
** COMMAND: purge*
448501
**
449502
** The purge command removes content from a repository and stores that content
@@ -540,11 +593,11 @@
540593
Blob content;
541594
if( g.argc<4 ) usage("cat HASH...");
542595
for(i=3; i<g.argc; i++){
543596
piid = db_int(0, "SELECT piid FROM purgeitem WHERE uuid LIKE '%q%%'",
544597
g.argv[i]);
545
- if( piid==0 ) fossil_fatal("no such item: %s", g.argv[3]);
598
+ if( piid==0 ) fossil_fatal("no such item: %s", g.argv[i]);
546599
purge_extract_item(piid, &content);
547600
blob_write_to_file(&content, "-");
548601
blob_reset(&content);
549602
}
550603
}else if( strncmp(zSubcmd, "checkins", n)==0 ){
@@ -551,18 +604,26 @@
551604
int vid;
552605
if( find_option("explain",0,0)!=0 || find_option("dry-run",0,0)!=0 ){
553606
purgeFlags |= PURGE_EXPLAIN_ONLY;
554607
}
555608
verify_all_options();
609
+ vid = 0;
610
+ if( g.localOpen ){
611
+ vid = db_lget_int("checkout",0);
612
+ }else if( db_open_local(0)
613
+ && db_exists("SELECT 1 WHERE inode(%Q)=inode(%Q)",
614
+ g.zRepositoryName, db_repository_filename())
615
+ ){
616
+ vid = db_lget_int("checkout",0);
617
+ }
556618
db_begin_transaction();
557619
if( g.argc<=3 ) usage("checkins TAGS... [OPTIONS]");
558620
db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
559621
for(i=3; i<g.argc; i++){
560622
int r = name_to_typed_rid(g.argv[i], "br");
561623
compute_descendants(r, 1000000000);
562624
}
563
- vid = db_lget_int("checkout",0);
564625
if( db_exists("SELECT 1 FROM ok WHERE rid=%d",vid) ){
565626
fossil_fatal("cannot purge the current check-out");
566627
}
567628
find_checkin_associates("ok", 1);
568629
purge_artifact_list("ok", "", purgeFlags);
@@ -610,11 +671,12 @@
610671
}
611672
}
612673
db_begin_transaction();
613674
for(i=3; i<g.argc; i++){
614675
int peid = atoi(g.argv[i]);
615
- if( !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
676
+ if( !db_table_exists("repository","purgeevent")
677
+ || !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
616678
fossil_fatal("no such purge event: %s", g.argv[i]);
617679
}
618680
db_multi_exec(
619681
"DELETE FROM purgeevent WHERE peid=%d;"
620682
"DELETE FROM purgeitem WHERE peid=%d;",
@@ -626,10 +688,14 @@
626688
fossil_fatal("not yet implemented....");
627689
}else if( strncmp(zSubcmd, "undo", n)==0 ){
628690
int peid;
629691
if( g.argc!=4 ) usage("undo ID");
630692
peid = atoi(g.argv[3]);
693
+ if( !db_table_exists("repository","purgeevent")
694
+ || !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
695
+ fossil_fatal("no such purge event: %s", g.argv[3]);
696
+ }
631697
if( (purgeFlags & PURGE_EXPLAIN_ONLY)==0 ){
632698
db_begin_transaction();
633699
db_multi_exec(
634700
"CREATE TEMP TABLE ix("
635701
" piid INTEGER PRIMARY KEY,"
@@ -645,10 +711,37 @@
645711
" WHERE uuid IN (SELECT uuid FROM purgeitem WHERE peid=%d);",
646712
peid
647713
);
648714
manifest_crosslink_begin();
649715
purge_item_resurrect(0, 0);
716
+ /* Relink check-ins whose purged parent is now restored */
717
+ db_multi_exec(
718
+ "CREATE TEMP TABLE prelink AS"
719
+ " SELECT DISTINCT mid FROM mlink"
720
+ " WHERE pmid IN (SELECT blob.rid FROM blob, purgeitem"
721
+ " WHERE purgeitem.peid=%d"
722
+ " AND blob.uuid=purgeitem.uuid"
723
+ " AND blob.rid=purgeitem.orid)"
724
+ " AND NOT EXISTS(SELECT 1 FROM plink"
725
+ " WHERE cid=mlink.mid AND pid=mlink.pmid)",
726
+ peid
727
+ );
728
+ db_prepare(&q, "SELECT mid FROM prelink");
729
+ while( db_step(&q)==SQLITE_ROW ){
730
+ int mid = db_column_int(&q, 0);
731
+ Blob c;
732
+ if( content_get(mid, &c) ){
733
+ db_multi_exec(
734
+ "DELETE FROM plink WHERE cid=%d;"
735
+ "DELETE FROM mlink WHERE mid=%d;",
736
+ mid, mid
737
+ );
738
+ manifest_crosslink(mid, &c, MC_NO_ERRORS);
739
+ }
740
+ }
741
+ db_finalize(&q);
742
+ db_multi_exec("DROP TABLE prelink");
650743
manifest_crosslink_end(0);
651744
db_multi_exec("DELETE FROM purgeevent WHERE peid=%d", peid);
652745
db_multi_exec("DELETE FROM purgeitem WHERE peid=%d", peid);
653746
db_end_transaction(0);
654747
}
655748
--- src/purge.c
+++ src/purge.c
@@ -401,19 +401,19 @@
401 fossil_fatal("delta loop while uncompressing purged artifacts");
402 }
403 bag_insert(&busy, iSrc);
404 }
405 db_prepare(&q,
406 "SELECT uuid, data, isPrivate, ix.piid"
407 " FROM ix, purgeitem"
408 " WHERE ix.srcid=%d"
409 " AND ix.piid=purgeitem.piid;",
410 iSrc
411 );
412 while( db_step(&q)==SQLITE_ROW ){
413 Blob h1, c1, c2;
414 int isPriv, rid;
415 blob_zero(&h1);
416 db_column_blob(&q, 0, &h1);
417 blob_zero(&c1);
418 db_column_blob(&q, 1, &c1);
419 blob_uncompress(&c1, &c1);
@@ -426,10 +426,26 @@
426 }
427 if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){
428 fossil_fatal("incorrect hash on %b", &h1);
429 }
430 isPriv = db_column_int(&q, 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431 rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
432 if( rid==0 ){
433 fossil_fatal("%s", g.zErrMsg);
434 }else{
435 if( !isPriv ) content_make_public(rid);
@@ -440,10 +456,47 @@
440 blob_reset(&c2);
441 }
442 db_finalize(&q);
443 if( iSrc>0 ) bag_remove(&busy, iSrc);
444 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
446 /*
447 ** COMMAND: purge*
448 **
449 ** The purge command removes content from a repository and stores that content
@@ -540,11 +593,11 @@
540 Blob content;
541 if( g.argc<4 ) usage("cat HASH...");
542 for(i=3; i<g.argc; i++){
543 piid = db_int(0, "SELECT piid FROM purgeitem WHERE uuid LIKE '%q%%'",
544 g.argv[i]);
545 if( piid==0 ) fossil_fatal("no such item: %s", g.argv[3]);
546 purge_extract_item(piid, &content);
547 blob_write_to_file(&content, "-");
548 blob_reset(&content);
549 }
550 }else if( strncmp(zSubcmd, "checkins", n)==0 ){
@@ -551,18 +604,26 @@
551 int vid;
552 if( find_option("explain",0,0)!=0 || find_option("dry-run",0,0)!=0 ){
553 purgeFlags |= PURGE_EXPLAIN_ONLY;
554 }
555 verify_all_options();
 
 
 
 
 
 
 
 
 
556 db_begin_transaction();
557 if( g.argc<=3 ) usage("checkins TAGS... [OPTIONS]");
558 db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
559 for(i=3; i<g.argc; i++){
560 int r = name_to_typed_rid(g.argv[i], "br");
561 compute_descendants(r, 1000000000);
562 }
563 vid = db_lget_int("checkout",0);
564 if( db_exists("SELECT 1 FROM ok WHERE rid=%d",vid) ){
565 fossil_fatal("cannot purge the current check-out");
566 }
567 find_checkin_associates("ok", 1);
568 purge_artifact_list("ok", "", purgeFlags);
@@ -610,11 +671,12 @@
610 }
611 }
612 db_begin_transaction();
613 for(i=3; i<g.argc; i++){
614 int peid = atoi(g.argv[i]);
615 if( !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
 
616 fossil_fatal("no such purge event: %s", g.argv[i]);
617 }
618 db_multi_exec(
619 "DELETE FROM purgeevent WHERE peid=%d;"
620 "DELETE FROM purgeitem WHERE peid=%d;",
@@ -626,10 +688,14 @@
626 fossil_fatal("not yet implemented....");
627 }else if( strncmp(zSubcmd, "undo", n)==0 ){
628 int peid;
629 if( g.argc!=4 ) usage("undo ID");
630 peid = atoi(g.argv[3]);
 
 
 
 
631 if( (purgeFlags & PURGE_EXPLAIN_ONLY)==0 ){
632 db_begin_transaction();
633 db_multi_exec(
634 "CREATE TEMP TABLE ix("
635 " piid INTEGER PRIMARY KEY,"
@@ -645,10 +711,37 @@
645 " WHERE uuid IN (SELECT uuid FROM purgeitem WHERE peid=%d);",
646 peid
647 );
648 manifest_crosslink_begin();
649 purge_item_resurrect(0, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650 manifest_crosslink_end(0);
651 db_multi_exec("DELETE FROM purgeevent WHERE peid=%d", peid);
652 db_multi_exec("DELETE FROM purgeitem WHERE peid=%d", peid);
653 db_end_transaction(0);
654 }
655
--- src/purge.c
+++ src/purge.c
@@ -401,19 +401,19 @@
401 fossil_fatal("delta loop while uncompressing purged artifacts");
402 }
403 bag_insert(&busy, iSrc);
404 }
405 db_prepare(&q,
406 "SELECT uuid, data, isPrivate, ix.piid, orid"
407 " FROM ix, purgeitem"
408 " WHERE ix.srcid=%d"
409 " AND ix.piid=purgeitem.piid;",
410 iSrc
411 );
412 while( db_step(&q)==SQLITE_ROW ){
413 Blob h1, c1, c2;
414 int isPriv, rid, orid;
415 blob_zero(&h1);
416 db_column_blob(&q, 0, &h1);
417 blob_zero(&c1);
418 db_column_blob(&q, 1, &c1);
419 blob_uncompress(&c1, &c1);
@@ -426,10 +426,26 @@
426 }
427 if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){
428 fossil_fatal("incorrect hash on %b", &h1);
429 }
430 isPriv = db_column_int(&q, 2);
431 orid = db_column_int(&q, 4);
432 if( orid>0
433 && !db_exists("SELECT 1 FROM blob WHERE rid=%d OR uuid=%Q",
434 orid, blob_str(&h1))
435 ){
436 /* Restore it under its old record number, which links still name */
437 db_multi_exec(
438 "INSERT INTO blob(rid,rcvid,size,uuid,content)"
439 " VALUES(%d,0,-1,%Q,NULL);"
440 "INSERT INTO phantom VALUES(%d);",
441 orid, blob_str(&h1), orid
442 );
443 if( !isPriv ){
444 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d)", orid);
445 }
446 }
447 rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
448 if( rid==0 ){
449 fossil_fatal("%s", g.zErrMsg);
450 }else{
451 if( !isPriv ) content_make_public(rid);
@@ -440,10 +456,47 @@
456 blob_reset(&c2);
457 }
458 db_finalize(&q);
459 if( iSrc>0 ) bag_remove(&busy, iSrc);
460 }
461
462 /*
463 ** Remove from the graveyard every artifact that was private when it was
464 ** purged, and any purge event left empty, so that "fossil scrub" leaves
465 ** no private content behind. An item that stays, but is stored as a
466 ** delta from one that goes, is stored whole first.
467 */
468 void purge_drop_private_items(void){
469 Stmt q;
470 if( !db_table_exists("repository","purgeitem") ) return;
471 db_multi_exec(
472 "CREATE TEMP TABLE pwhole AS"
473 " SELECT piid FROM purgeitem WHERE NOT isPrivate"
474 " AND srcid IN (SELECT piid FROM purgeitem WHERE isPrivate)"
475 );
476 db_prepare(&q, "SELECT piid FROM pwhole");
477 while( db_step(&q)==SQLITE_ROW ){
478 int piid = db_column_int(&q, 0);
479 Blob content, cmpr;
480 Stmt u;
481 purge_extract_item(piid, &content);
482 blob_compress(&content, &cmpr);
483 db_prepare(&u, "UPDATE purgeitem SET srcid=NULL, data=:data"
484 " WHERE piid=%d", piid);
485 db_bind_blob(&u, ":data", &cmpr);
486 db_exec(&u);
487 db_finalize(&u);
488 blob_reset(&content);
489 blob_reset(&cmpr);
490 }
491 db_finalize(&q);
492 db_multi_exec(
493 "DROP TABLE pwhole;"
494 "DELETE FROM purgeitem WHERE isPrivate;"
495 "DELETE FROM purgeevent WHERE peid NOT IN (SELECT peid FROM purgeitem);"
496 );
497 }
498
499 /*
500 ** COMMAND: purge*
501 **
502 ** The purge command removes content from a repository and stores that content
@@ -540,11 +593,11 @@
593 Blob content;
594 if( g.argc<4 ) usage("cat HASH...");
595 for(i=3; i<g.argc; i++){
596 piid = db_int(0, "SELECT piid FROM purgeitem WHERE uuid LIKE '%q%%'",
597 g.argv[i]);
598 if( piid==0 ) fossil_fatal("no such item: %s", g.argv[i]);
599 purge_extract_item(piid, &content);
600 blob_write_to_file(&content, "-");
601 blob_reset(&content);
602 }
603 }else if( strncmp(zSubcmd, "checkins", n)==0 ){
@@ -551,18 +604,26 @@
604 int vid;
605 if( find_option("explain",0,0)!=0 || find_option("dry-run",0,0)!=0 ){
606 purgeFlags |= PURGE_EXPLAIN_ONLY;
607 }
608 verify_all_options();
609 vid = 0;
610 if( g.localOpen ){
611 vid = db_lget_int("checkout",0);
612 }else if( db_open_local(0)
613 && db_exists("SELECT 1 WHERE inode(%Q)=inode(%Q)",
614 g.zRepositoryName, db_repository_filename())
615 ){
616 vid = db_lget_int("checkout",0);
617 }
618 db_begin_transaction();
619 if( g.argc<=3 ) usage("checkins TAGS... [OPTIONS]");
620 db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
621 for(i=3; i<g.argc; i++){
622 int r = name_to_typed_rid(g.argv[i], "br");
623 compute_descendants(r, 1000000000);
624 }
 
625 if( db_exists("SELECT 1 FROM ok WHERE rid=%d",vid) ){
626 fossil_fatal("cannot purge the current check-out");
627 }
628 find_checkin_associates("ok", 1);
629 purge_artifact_list("ok", "", purgeFlags);
@@ -610,11 +671,12 @@
671 }
672 }
673 db_begin_transaction();
674 for(i=3; i<g.argc; i++){
675 int peid = atoi(g.argv[i]);
676 if( !db_table_exists("repository","purgeevent")
677 || !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
678 fossil_fatal("no such purge event: %s", g.argv[i]);
679 }
680 db_multi_exec(
681 "DELETE FROM purgeevent WHERE peid=%d;"
682 "DELETE FROM purgeitem WHERE peid=%d;",
@@ -626,10 +688,14 @@
688 fossil_fatal("not yet implemented....");
689 }else if( strncmp(zSubcmd, "undo", n)==0 ){
690 int peid;
691 if( g.argc!=4 ) usage("undo ID");
692 peid = atoi(g.argv[3]);
693 if( !db_table_exists("repository","purgeevent")
694 || !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
695 fossil_fatal("no such purge event: %s", g.argv[3]);
696 }
697 if( (purgeFlags & PURGE_EXPLAIN_ONLY)==0 ){
698 db_begin_transaction();
699 db_multi_exec(
700 "CREATE TEMP TABLE ix("
701 " piid INTEGER PRIMARY KEY,"
@@ -645,10 +711,37 @@
711 " WHERE uuid IN (SELECT uuid FROM purgeitem WHERE peid=%d);",
712 peid
713 );
714 manifest_crosslink_begin();
715 purge_item_resurrect(0, 0);
716 /* Relink check-ins whose purged parent is now restored */
717 db_multi_exec(
718 "CREATE TEMP TABLE prelink AS"
719 " SELECT DISTINCT mid FROM mlink"
720 " WHERE pmid IN (SELECT blob.rid FROM blob, purgeitem"
721 " WHERE purgeitem.peid=%d"
722 " AND blob.uuid=purgeitem.uuid"
723 " AND blob.rid=purgeitem.orid)"
724 " AND NOT EXISTS(SELECT 1 FROM plink"
725 " WHERE cid=mlink.mid AND pid=mlink.pmid)",
726 peid
727 );
728 db_prepare(&q, "SELECT mid FROM prelink");
729 while( db_step(&q)==SQLITE_ROW ){
730 int mid = db_column_int(&q, 0);
731 Blob c;
732 if( content_get(mid, &c) ){
733 db_multi_exec(
734 "DELETE FROM plink WHERE cid=%d;"
735 "DELETE FROM mlink WHERE mid=%d;",
736 mid, mid
737 );
738 manifest_crosslink(mid, &c, MC_NO_ERRORS);
739 }
740 }
741 db_finalize(&q);
742 db_multi_exec("DROP TABLE prelink");
743 manifest_crosslink_end(0);
744 db_multi_exec("DELETE FROM purgeevent WHERE peid=%d", peid);
745 db_multi_exec("DELETE FROM purgeitem WHERE peid=%d", peid);
746 db_end_transaction(0);
747 }
748
--- src/rebuild.c
+++ src/rebuild.c
@@ -1058,10 +1058,11 @@
10581058
}
10591059
db_begin_transaction();
10601060
if( privateOnly || bVerily ){
10611061
bNeedRebuild = db_exists("SELECT 1 FROM private");
10621062
delete_private_content();
1063
+ purge_drop_private_items();
10631064
}
10641065
if( !privateOnly ){
10651066
db_unprotect(PROTECT_ALL);
10661067
db_multi_exec(
10671068
"PRAGMA secure_delete=ON;"
10681069
--- src/rebuild.c
+++ src/rebuild.c
@@ -1058,10 +1058,11 @@
1058 }
1059 db_begin_transaction();
1060 if( privateOnly || bVerily ){
1061 bNeedRebuild = db_exists("SELECT 1 FROM private");
1062 delete_private_content();
 
1063 }
1064 if( !privateOnly ){
1065 db_unprotect(PROTECT_ALL);
1066 db_multi_exec(
1067 "PRAGMA secure_delete=ON;"
1068
--- src/rebuild.c
+++ src/rebuild.c
@@ -1058,10 +1058,11 @@
1058 }
1059 db_begin_transaction();
1060 if( privateOnly || bVerily ){
1061 bNeedRebuild = db_exists("SELECT 1 FROM private");
1062 delete_private_content();
1063 purge_drop_private_items();
1064 }
1065 if( !privateOnly ){
1066 db_unprotect(PROTECT_ALL);
1067 db_multi_exec(
1068 "PRAGMA secure_delete=ON;"
1069
+17 -12
--- src/th.c
+++ src/th.c
@@ -947,11 +947,11 @@
947947
zInput += nSpace;
948948
nInput -= nSpace;
949949
zFirst = zInput;
950950
951951
/* Check for a comment. If found, skip to the end of the line. */
952
- if( zInput[0]=='#' ){
952
+ if( nInput>0 && zInput[0]=='#' ){
953953
while( !thEndOfLine(zInput, nInput) ){
954954
zInput++;
955955
nInput--;
956956
}
957957
continue;
@@ -958,11 +958,11 @@
958958
}
959959
960960
/* Gobble up input a word at a time until the end of the command
961961
** (a semi-colon or end of line).
962962
*/
963
- while( rc==TH_OK && *zInput!=';' && !thEndOfLine(zInput, nInput) ){
963
+ while( rc==TH_OK && !thEndOfLine(zInput, nInput) && *zInput!=';' ){
964964
int nWord=0;
965965
thNextSpace(interp, zInput, nInput, &nSpace);
966966
rc = thNextWord(interp, &zInput[nSpace], nInput-nSpace, &nWord, 1);
967967
zInput += (nSpace+nWord);
968968
nInput -= (nSpace+nWord);
@@ -2166,31 +2166,33 @@
21662166
}
21672167
}
21682168
}
21692169
21702170
if( rc==TH_OK && eArgType==ARG_INTEGER ){
2171
+ unsigned int uLeft = (unsigned int)iLeft;
2172
+ unsigned int uRight = (unsigned int)iRight;
21712173
int iRes = 0;
21722174
switch( pExpr->pOp->eOp ) {
2173
- case OP_MULTIPLY: iRes = iLeft*iRight; break;
2175
+ case OP_MULTIPLY: iRes = (int)(uLeft*uRight); break;
21742176
case OP_DIVIDE:
21752177
if( !iRight ){
21762178
Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
21772179
rc = TH_ERROR;
21782180
goto finish;
21792181
}
2180
- iRes = iLeft/iRight;
2182
+ iRes = iRight==(-1) ? (int)(0u-uLeft) : iLeft/iRight;
21812183
break;
21822184
case OP_MODULUS:
21832185
if( !iRight ){
21842186
Th_ErrorMessage(interp, "Modulo by 0:", zLeft, nLeft);
21852187
rc = TH_ERROR;
21862188
goto finish;
21872189
}
2188
- iRes = iLeft%iRight;
2190
+ iRes = iRight==(-1) ? 0 : iLeft%iRight;
21892191
break;
2190
- case OP_ADD: iRes = iLeft+iRight; break;
2191
- case OP_SUBTRACT: iRes = iLeft-iRight; break;
2192
+ case OP_ADD: iRes = (int)(uLeft+uRight); break;
2193
+ case OP_SUBTRACT: iRes = (int)(uLeft-uRight); break;
21922194
case OP_LEFTSHIFT: {
21932195
iRes = (int)(((unsigned int)iLeft)<<(iRight&0x1f));
21942196
break;
21952197
}
21962198
case OP_RIGHTSHIFT: iRes = iLeft>>(iRight&0x1f); break;
@@ -2203,11 +2205,11 @@
22032205
case OP_BITWISE_AND: iRes = iLeft&iRight; break;
22042206
case OP_BITWISE_XOR: iRes = iLeft^iRight; break;
22052207
case OP_BITWISE_OR: iRes = iLeft|iRight; break;
22062208
case OP_LOGICAL_AND: iRes = iLeft&&iRight; break;
22072209
case OP_LOGICAL_OR: iRes = iLeft||iRight; break;
2208
- case OP_UNARY_MINUS: iRes = -iLeft; break;
2210
+ case OP_UNARY_MINUS: iRes = (int)(0u-uLeft); break;
22092211
case OP_UNARY_PLUS: iRes = +iLeft; break;
22102212
case OP_BITWISE_NOT: iRes = ~iLeft; break;
22112213
case OP_LOGICAL_NOT: iRes = !iLeft; break;
22122214
default: assert(!"Internal error");
22132215
}
@@ -2822,14 +2824,17 @@
28222824
** If successful, store the result in *piOut and return TH_OK.
28232825
**
28242826
** If the string cannot be converted to an integer, return TH_ERROR.
28252827
** If the interp argument is not NULL, leave an error message in the
28262828
** interpreter result too.
2829
+**
2830
+** A value too large for an int wraps around. The arithmetic is done on
2831
+** an unsigned int, for which that is defined.
28272832
*/
28282833
int Th_ToInt(Th_Interp *interp, const char *z, int n, int *piOut){
28292834
int i = 0;
2830
- int iOut = 0;
2835
+ unsigned int iOut = 0;
28312836
int base = 10;
28322837
int (*isdigit)(char) = th_isdigit;
28332838
28342839
if( n<0 ){
28352840
n = th_strlen(z);
@@ -2866,18 +2871,18 @@
28662871
}else if( c>='A' ){
28672872
c -= 'A'-10;
28682873
}else{
28692874
c -= '0';
28702875
}
2871
- iOut = iOut * base + c;
2876
+ iOut = iOut * (unsigned int)base + (unsigned int)c;
28722877
}
28732878
28742879
if( n>0 && z[0]=='-' ){
2875
- iOut *= -1;
2880
+ iOut = 0u - iOut;
28762881
}
28772882
2878
- *piOut = iOut;
2883
+ *piOut = (int)iOut;
28792884
return TH_OK;
28802885
}
28812886
28822887
/*
28832888
** Try to convert the string passed as arguments (z, n) to a double.
28842889
--- src/th.c
+++ src/th.c
@@ -947,11 +947,11 @@
947 zInput += nSpace;
948 nInput -= nSpace;
949 zFirst = zInput;
950
951 /* Check for a comment. If found, skip to the end of the line. */
952 if( zInput[0]=='#' ){
953 while( !thEndOfLine(zInput, nInput) ){
954 zInput++;
955 nInput--;
956 }
957 continue;
@@ -958,11 +958,11 @@
958 }
959
960 /* Gobble up input a word at a time until the end of the command
961 ** (a semi-colon or end of line).
962 */
963 while( rc==TH_OK && *zInput!=';' && !thEndOfLine(zInput, nInput) ){
964 int nWord=0;
965 thNextSpace(interp, zInput, nInput, &nSpace);
966 rc = thNextWord(interp, &zInput[nSpace], nInput-nSpace, &nWord, 1);
967 zInput += (nSpace+nWord);
968 nInput -= (nSpace+nWord);
@@ -2166,31 +2166,33 @@
2166 }
2167 }
2168 }
2169
2170 if( rc==TH_OK && eArgType==ARG_INTEGER ){
 
 
2171 int iRes = 0;
2172 switch( pExpr->pOp->eOp ) {
2173 case OP_MULTIPLY: iRes = iLeft*iRight; break;
2174 case OP_DIVIDE:
2175 if( !iRight ){
2176 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
2177 rc = TH_ERROR;
2178 goto finish;
2179 }
2180 iRes = iLeft/iRight;
2181 break;
2182 case OP_MODULUS:
2183 if( !iRight ){
2184 Th_ErrorMessage(interp, "Modulo by 0:", zLeft, nLeft);
2185 rc = TH_ERROR;
2186 goto finish;
2187 }
2188 iRes = iLeft%iRight;
2189 break;
2190 case OP_ADD: iRes = iLeft+iRight; break;
2191 case OP_SUBTRACT: iRes = iLeft-iRight; break;
2192 case OP_LEFTSHIFT: {
2193 iRes = (int)(((unsigned int)iLeft)<<(iRight&0x1f));
2194 break;
2195 }
2196 case OP_RIGHTSHIFT: iRes = iLeft>>(iRight&0x1f); break;
@@ -2203,11 +2205,11 @@
2203 case OP_BITWISE_AND: iRes = iLeft&iRight; break;
2204 case OP_BITWISE_XOR: iRes = iLeft^iRight; break;
2205 case OP_BITWISE_OR: iRes = iLeft|iRight; break;
2206 case OP_LOGICAL_AND: iRes = iLeft&&iRight; break;
2207 case OP_LOGICAL_OR: iRes = iLeft||iRight; break;
2208 case OP_UNARY_MINUS: iRes = -iLeft; break;
2209 case OP_UNARY_PLUS: iRes = +iLeft; break;
2210 case OP_BITWISE_NOT: iRes = ~iLeft; break;
2211 case OP_LOGICAL_NOT: iRes = !iLeft; break;
2212 default: assert(!"Internal error");
2213 }
@@ -2822,14 +2824,17 @@
2822 ** If successful, store the result in *piOut and return TH_OK.
2823 **
2824 ** If the string cannot be converted to an integer, return TH_ERROR.
2825 ** If the interp argument is not NULL, leave an error message in the
2826 ** interpreter result too.
 
 
 
2827 */
2828 int Th_ToInt(Th_Interp *interp, const char *z, int n, int *piOut){
2829 int i = 0;
2830 int iOut = 0;
2831 int base = 10;
2832 int (*isdigit)(char) = th_isdigit;
2833
2834 if( n<0 ){
2835 n = th_strlen(z);
@@ -2866,18 +2871,18 @@
2866 }else if( c>='A' ){
2867 c -= 'A'-10;
2868 }else{
2869 c -= '0';
2870 }
2871 iOut = iOut * base + c;
2872 }
2873
2874 if( n>0 && z[0]=='-' ){
2875 iOut *= -1;
2876 }
2877
2878 *piOut = iOut;
2879 return TH_OK;
2880 }
2881
2882 /*
2883 ** Try to convert the string passed as arguments (z, n) to a double.
2884
--- src/th.c
+++ src/th.c
@@ -947,11 +947,11 @@
947 zInput += nSpace;
948 nInput -= nSpace;
949 zFirst = zInput;
950
951 /* Check for a comment. If found, skip to the end of the line. */
952 if( nInput>0 && zInput[0]=='#' ){
953 while( !thEndOfLine(zInput, nInput) ){
954 zInput++;
955 nInput--;
956 }
957 continue;
@@ -958,11 +958,11 @@
958 }
959
960 /* Gobble up input a word at a time until the end of the command
961 ** (a semi-colon or end of line).
962 */
963 while( rc==TH_OK && !thEndOfLine(zInput, nInput) && *zInput!=';' ){
964 int nWord=0;
965 thNextSpace(interp, zInput, nInput, &nSpace);
966 rc = thNextWord(interp, &zInput[nSpace], nInput-nSpace, &nWord, 1);
967 zInput += (nSpace+nWord);
968 nInput -= (nSpace+nWord);
@@ -2166,31 +2166,33 @@
2166 }
2167 }
2168 }
2169
2170 if( rc==TH_OK && eArgType==ARG_INTEGER ){
2171 unsigned int uLeft = (unsigned int)iLeft;
2172 unsigned int uRight = (unsigned int)iRight;
2173 int iRes = 0;
2174 switch( pExpr->pOp->eOp ) {
2175 case OP_MULTIPLY: iRes = (int)(uLeft*uRight); break;
2176 case OP_DIVIDE:
2177 if( !iRight ){
2178 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
2179 rc = TH_ERROR;
2180 goto finish;
2181 }
2182 iRes = iRight==(-1) ? (int)(0u-uLeft) : iLeft/iRight;
2183 break;
2184 case OP_MODULUS:
2185 if( !iRight ){
2186 Th_ErrorMessage(interp, "Modulo by 0:", zLeft, nLeft);
2187 rc = TH_ERROR;
2188 goto finish;
2189 }
2190 iRes = iRight==(-1) ? 0 : iLeft%iRight;
2191 break;
2192 case OP_ADD: iRes = (int)(uLeft+uRight); break;
2193 case OP_SUBTRACT: iRes = (int)(uLeft-uRight); break;
2194 case OP_LEFTSHIFT: {
2195 iRes = (int)(((unsigned int)iLeft)<<(iRight&0x1f));
2196 break;
2197 }
2198 case OP_RIGHTSHIFT: iRes = iLeft>>(iRight&0x1f); break;
@@ -2203,11 +2205,11 @@
2205 case OP_BITWISE_AND: iRes = iLeft&iRight; break;
2206 case OP_BITWISE_XOR: iRes = iLeft^iRight; break;
2207 case OP_BITWISE_OR: iRes = iLeft|iRight; break;
2208 case OP_LOGICAL_AND: iRes = iLeft&&iRight; break;
2209 case OP_LOGICAL_OR: iRes = iLeft||iRight; break;
2210 case OP_UNARY_MINUS: iRes = (int)(0u-uLeft); break;
2211 case OP_UNARY_PLUS: iRes = +iLeft; break;
2212 case OP_BITWISE_NOT: iRes = ~iLeft; break;
2213 case OP_LOGICAL_NOT: iRes = !iLeft; break;
2214 default: assert(!"Internal error");
2215 }
@@ -2822,14 +2824,17 @@
2824 ** If successful, store the result in *piOut and return TH_OK.
2825 **
2826 ** If the string cannot be converted to an integer, return TH_ERROR.
2827 ** If the interp argument is not NULL, leave an error message in the
2828 ** interpreter result too.
2829 **
2830 ** A value too large for an int wraps around. The arithmetic is done on
2831 ** an unsigned int, for which that is defined.
2832 */
2833 int Th_ToInt(Th_Interp *interp, const char *z, int n, int *piOut){
2834 int i = 0;
2835 unsigned int iOut = 0;
2836 int base = 10;
2837 int (*isdigit)(char) = th_isdigit;
2838
2839 if( n<0 ){
2840 n = th_strlen(z);
@@ -2866,18 +2871,18 @@
2871 }else if( c>='A' ){
2872 c -= 'A'-10;
2873 }else{
2874 c -= '0';
2875 }
2876 iOut = iOut * (unsigned int)base + (unsigned int)c;
2877 }
2878
2879 if( n>0 && z[0]=='-' ){
2880 iOut = 0u - iOut;
2881 }
2882
2883 *piOut = (int)iOut;
2884 return TH_OK;
2885 }
2886
2887 /*
2888 ** Try to convert the string passed as arguments (z, n) to a double.
2889
+76 -11
--- src/xfer.c
+++ src/xfer.c
@@ -256,16 +256,21 @@
256256
**
257257
** The original size of the HASH artifact is USIZE.
258258
**
259259
** If any error occurs, write a message into pErr which has already
260260
** be initialized to an empty string.
261
+**
262
+** Unless cloneFlag is set, the content must have the size USIZE and
263
+** give the HASH, or it is refused. The hash of a delta is checked only
264
+** if DELTASRC is at hand. A clone is not checked here.
261265
**
262266
** Any artifact successfully received by this routine is considered to
263267
** be public and is therefore removed from the "private" table.
264268
*/
265269
static void xfer_accept_compressed_file(
266270
Xfer *pXfer,
271
+ int cloneFlag,
267272
char **pzUuidList,
268273
int *pnUuidList
269274
){
270275
int szC; /* CSIZE */
271276
int szU; /* USIZE */
@@ -299,20 +304,60 @@
299304
}
300305
if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
301306
/* Ignore files that have been shunned */
302307
blob_reset(&content);
303308
return;
309
+ }
310
+ if( szU==0
311
+ && (blob_size(&content)<=4 || blob_uncompress(&content, &content))
312
+ ){
313
+ blob_appendf(&pXfer->err, "malformed cfile content");
314
+ blob_reset(&content);
315
+ return;
304316
}
305317
if( pXfer->nToken==5 ){
306318
srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
307319
pXfer->nDeltaRcvd++;
308320
}else{
309321
srcid = 0;
310322
pXfer->nFileRcvd++;
323
+ }
324
+ if( !cloneFlag ){
325
+ Blob *pUuid = &pXfer->aToken[1];
326
+ Blob x; /* The content, uncompressed */
327
+ Blob src, next; /* Source of a delta, and the delta applied to it */
328
+ int ok = 1;
329
+ blob_zero(&x);
330
+ if( szU==0 ){
331
+ blob_copy(&x, &content);
332
+ }else if( blob_size(&content)<=4 || blob_uncompress(&content, &x) ){
333
+ blob_appendf(&pXfer->err, "malformed cfile content");
334
+ blob_reset(&content);
335
+ return;
336
+ }
337
+ if( srcid==0 ){
338
+ ok = (int)blob_size(&x)==szU
339
+ && hname_verify_hash(&x, blob_buffer(pUuid), blob_size(pUuid));
340
+ }else if( delta_output_size(blob_buffer(&x), blob_size(&x))!=szU ){
341
+ ok = 0;
342
+ }else if( content_get(srcid, &src) ){
343
+ blob_zero(&next);
344
+ ok = blob_delta_apply(&src, &x, &next)>=0
345
+ && hname_verify_hash(&next, blob_buffer(pUuid), blob_size(pUuid));
346
+ blob_reset(&next);
347
+ blob_reset(&src);
348
+ }
349
+ blob_reset(&x);
350
+ if( !ok ){
351
+ blob_appendf(&pXfer->err,
352
+ "wrong size or hash on received artifact: %b", pUuid);
353
+ blob_reset(&content);
354
+ return;
355
+ }
311356
}
312357
rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
313
- szC, isPriv);
358
+ szU, isPriv);
314359
Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]),
315360
blob_size(&pXfer->aToken[1]));
316361
remote_has(rid);
317362
blob_reset(&content);
318363
}
@@ -381,10 +426,13 @@
381426
goto end_accept_unversioned_file;
382427
}
383428
384429
/* Make sure we have a valid g.rcvid marker */
385430
content_rcvid_init(0);
431
+
432
+ /* The table might not exist yet if the other side sent no uv-hash pragma */
433
+ unversioned_schema();
386434
387435
/* Check to see if current content really should be overwritten. Ideally,
388436
** a uvfile card should never have been sent unless the overwrite should
389437
** occur. But do not trust the sender. Double-check.
390438
*/
@@ -737,10 +785,11 @@
737785
int isClient /* True if sending from client to server */
738786
){
739787
Stmt q1;
740788
int isFull = !isClient && (int)blob_size(pXfer->pOut)>=pXfer->mxSend;
741789
790
+ unversioned_schema();
742791
if( isFull ) noContent = 1;
743792
if( noContent ){
744793
db_prepare(&q1,
745794
"SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
746795
zName
@@ -1415,11 +1464,11 @@
14151464
cgi_reset_content();
14161465
@ error not\sauthorized\sto\swrite%s(whyNotAuth())
14171466
nErr++;
14181467
break;
14191468
}
1420
- xfer_accept_compressed_file(&xfer, pzUuidList, pnUuidList);
1469
+ xfer_accept_compressed_file(&xfer, 0, pzUuidList, pnUuidList);
14211470
if( blob_size(&xfer.err) ){
14221471
cgi_reset_content();
14231472
@ error %T(blob_str(&xfer.err))
14241473
nErr++;
14251474
break;
@@ -2097,10 +2146,22 @@
20972146
** Floating-point absolute value
20982147
*/
20992148
static double fossil_fabs(double x){
21002149
return x>0.0 ? x : -x;
21012150
}
2151
+
2152
+/*
2153
+** Tell the user that unversioned content cannot be pushed because the
2154
+** server has sent the "uv-pull-only" pragma.
2155
+*/
2156
+static void uv_pull_only_warning(void){
2157
+ fossil_warning(
2158
+ "Warning: uv-pull-only \n"
2159
+ " Unable to push unversioned content because you lack\n"
2160
+ " sufficient permission on the server\n"
2161
+ );
2162
+}
21022163
21032164
/*
21042165
** Sync to the host identified in g.url.name and g.url.path. This
21052166
** routine is called by the client.
21062167
**
@@ -2176,14 +2237,13 @@
21762237
const char *zPX;
21772238
configRcvMask = 0;
21782239
configSendMask = 0;
21792240
syncFlags &= ~(SYNC_PUSH);
21802241
zPX = db_get("parent-project-code", 0);
2181
- if( zPX==0 || db_get("parent-project-name",0)==0 ){
2242
+ if( zPX==0 ){
21822243
fossil_fatal("there is no parent project: set the 'parent-project-code'"
2183
- " and 'parent-project-name' config parameters in order"
2184
- " to pull from a parent project");
2244
+ " config parameter in order to pull from a parent project");
21852245
}
21862246
if( zPX ){
21872247
zAltPCode = zPX;
21882248
}
21892249
}
@@ -2584,11 +2644,11 @@
25842644
** Client receives a compressed file transmitted from the server.
25852645
*/
25862646
if( blob_eq(&xfer.aToken[0],"cfile")
25872647
&& (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0
25882648
){
2589
- xfer_accept_compressed_file(&xfer, 0, 0);
2649
+ xfer_accept_compressed_file(&xfer, (syncFlags & SYNC_CLONE)!=0, 0, 0);
25902650
nArtifactRcvd++;
25912651
}else
25922652
25932653
/* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
25942654
**
@@ -2731,15 +2791,11 @@
27312791
"UPDATE unversioned SET mtime=%lld WHERE name=%Q", mtime, zName
27322792
);
27332793
db_unset("uv-hash", 0);
27342794
}
27352795
if( iStatus>=4 && uvPullOnly==1 ){
2736
- fossil_warning(
2737
- "Warning: uv-pull-only \n"
2738
- " Unable to push unversioned content because you lack\n"
2739
- " sufficient permission on the server\n"
2740
- );
2796
+ uv_pull_only_warning();
27412797
uvPullOnly = 2;
27422798
}
27432799
if( iStatus<=3 || uvPullOnly ){
27442800
db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
27452801
}else if( iStatus==4 ){
@@ -3039,10 +3095,19 @@
30393095
}
30403096
}
30413097
nUncRcvd += blob_size(&recv);
30423098
blob_reset(&recv);
30433099
nCycle++;
3100
+
3101
+ /* Also warn for files that no uvigot card named */
3102
+ if( uvPullOnly==1 && (syncFlags & SYNC_UV_REVERT)==0
3103
+ && db_exists("SELECT 1 FROM uv_tosend")
3104
+ ){
3105
+ uv_pull_only_warning();
3106
+ uvPullOnly = 2;
3107
+ db_multi_exec("DELETE FROM uv_tosend");
3108
+ }
30443109
30453110
/* Set go to 1 if we need to continue the sync/push/pull/clone for
30463111
** another round. Set go to 0 if it is time to quit. */
30473112
nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
30483113
if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
30493114
--- src/xfer.c
+++ src/xfer.c
@@ -256,16 +256,21 @@
256 **
257 ** The original size of the HASH artifact is USIZE.
258 **
259 ** If any error occurs, write a message into pErr which has already
260 ** be initialized to an empty string.
 
 
 
 
261 **
262 ** Any artifact successfully received by this routine is considered to
263 ** be public and is therefore removed from the "private" table.
264 */
265 static void xfer_accept_compressed_file(
266 Xfer *pXfer,
 
267 char **pzUuidList,
268 int *pnUuidList
269 ){
270 int szC; /* CSIZE */
271 int szU; /* USIZE */
@@ -299,20 +304,60 @@
299 }
300 if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
301 /* Ignore files that have been shunned */
302 blob_reset(&content);
303 return;
 
 
 
 
 
 
 
304 }
305 if( pXfer->nToken==5 ){
306 srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
307 pXfer->nDeltaRcvd++;
308 }else{
309 srcid = 0;
310 pXfer->nFileRcvd++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311 }
312 rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
313 szC, isPriv);
314 Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]),
315 blob_size(&pXfer->aToken[1]));
316 remote_has(rid);
317 blob_reset(&content);
318 }
@@ -381,10 +426,13 @@
381 goto end_accept_unversioned_file;
382 }
383
384 /* Make sure we have a valid g.rcvid marker */
385 content_rcvid_init(0);
 
 
 
386
387 /* Check to see if current content really should be overwritten. Ideally,
388 ** a uvfile card should never have been sent unless the overwrite should
389 ** occur. But do not trust the sender. Double-check.
390 */
@@ -737,10 +785,11 @@
737 int isClient /* True if sending from client to server */
738 ){
739 Stmt q1;
740 int isFull = !isClient && (int)blob_size(pXfer->pOut)>=pXfer->mxSend;
741
 
742 if( isFull ) noContent = 1;
743 if( noContent ){
744 db_prepare(&q1,
745 "SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
746 zName
@@ -1415,11 +1464,11 @@
1415 cgi_reset_content();
1416 @ error not\sauthorized\sto\swrite%s(whyNotAuth())
1417 nErr++;
1418 break;
1419 }
1420 xfer_accept_compressed_file(&xfer, pzUuidList, pnUuidList);
1421 if( blob_size(&xfer.err) ){
1422 cgi_reset_content();
1423 @ error %T(blob_str(&xfer.err))
1424 nErr++;
1425 break;
@@ -2097,10 +2146,22 @@
2097 ** Floating-point absolute value
2098 */
2099 static double fossil_fabs(double x){
2100 return x>0.0 ? x : -x;
2101 }
 
 
 
 
 
 
 
 
 
 
 
 
2102
2103 /*
2104 ** Sync to the host identified in g.url.name and g.url.path. This
2105 ** routine is called by the client.
2106 **
@@ -2176,14 +2237,13 @@
2176 const char *zPX;
2177 configRcvMask = 0;
2178 configSendMask = 0;
2179 syncFlags &= ~(SYNC_PUSH);
2180 zPX = db_get("parent-project-code", 0);
2181 if( zPX==0 || db_get("parent-project-name",0)==0 ){
2182 fossil_fatal("there is no parent project: set the 'parent-project-code'"
2183 " and 'parent-project-name' config parameters in order"
2184 " to pull from a parent project");
2185 }
2186 if( zPX ){
2187 zAltPCode = zPX;
2188 }
2189 }
@@ -2584,11 +2644,11 @@
2584 ** Client receives a compressed file transmitted from the server.
2585 */
2586 if( blob_eq(&xfer.aToken[0],"cfile")
2587 && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0
2588 ){
2589 xfer_accept_compressed_file(&xfer, 0, 0);
2590 nArtifactRcvd++;
2591 }else
2592
2593 /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
2594 **
@@ -2731,15 +2791,11 @@
2731 "UPDATE unversioned SET mtime=%lld WHERE name=%Q", mtime, zName
2732 );
2733 db_unset("uv-hash", 0);
2734 }
2735 if( iStatus>=4 && uvPullOnly==1 ){
2736 fossil_warning(
2737 "Warning: uv-pull-only \n"
2738 " Unable to push unversioned content because you lack\n"
2739 " sufficient permission on the server\n"
2740 );
2741 uvPullOnly = 2;
2742 }
2743 if( iStatus<=3 || uvPullOnly ){
2744 db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
2745 }else if( iStatus==4 ){
@@ -3039,10 +3095,19 @@
3039 }
3040 }
3041 nUncRcvd += blob_size(&recv);
3042 blob_reset(&recv);
3043 nCycle++;
 
 
 
 
 
 
 
 
 
3044
3045 /* Set go to 1 if we need to continue the sync/push/pull/clone for
3046 ** another round. Set go to 0 if it is time to quit. */
3047 nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
3048 if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
3049
--- src/xfer.c
+++ src/xfer.c
@@ -256,16 +256,21 @@
256 **
257 ** The original size of the HASH artifact is USIZE.
258 **
259 ** If any error occurs, write a message into pErr which has already
260 ** be initialized to an empty string.
261 **
262 ** Unless cloneFlag is set, the content must have the size USIZE and
263 ** give the HASH, or it is refused. The hash of a delta is checked only
264 ** if DELTASRC is at hand. A clone is not checked here.
265 **
266 ** Any artifact successfully received by this routine is considered to
267 ** be public and is therefore removed from the "private" table.
268 */
269 static void xfer_accept_compressed_file(
270 Xfer *pXfer,
271 int cloneFlag,
272 char **pzUuidList,
273 int *pnUuidList
274 ){
275 int szC; /* CSIZE */
276 int szU; /* USIZE */
@@ -299,20 +304,60 @@
304 }
305 if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
306 /* Ignore files that have been shunned */
307 blob_reset(&content);
308 return;
309 }
310 if( szU==0
311 && (blob_size(&content)<=4 || blob_uncompress(&content, &content))
312 ){
313 blob_appendf(&pXfer->err, "malformed cfile content");
314 blob_reset(&content);
315 return;
316 }
317 if( pXfer->nToken==5 ){
318 srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
319 pXfer->nDeltaRcvd++;
320 }else{
321 srcid = 0;
322 pXfer->nFileRcvd++;
323 }
324 if( !cloneFlag ){
325 Blob *pUuid = &pXfer->aToken[1];
326 Blob x; /* The content, uncompressed */
327 Blob src, next; /* Source of a delta, and the delta applied to it */
328 int ok = 1;
329 blob_zero(&x);
330 if( szU==0 ){
331 blob_copy(&x, &content);
332 }else if( blob_size(&content)<=4 || blob_uncompress(&content, &x) ){
333 blob_appendf(&pXfer->err, "malformed cfile content");
334 blob_reset(&content);
335 return;
336 }
337 if( srcid==0 ){
338 ok = (int)blob_size(&x)==szU
339 && hname_verify_hash(&x, blob_buffer(pUuid), blob_size(pUuid));
340 }else if( delta_output_size(blob_buffer(&x), blob_size(&x))!=szU ){
341 ok = 0;
342 }else if( content_get(srcid, &src) ){
343 blob_zero(&next);
344 ok = blob_delta_apply(&src, &x, &next)>=0
345 && hname_verify_hash(&next, blob_buffer(pUuid), blob_size(pUuid));
346 blob_reset(&next);
347 blob_reset(&src);
348 }
349 blob_reset(&x);
350 if( !ok ){
351 blob_appendf(&pXfer->err,
352 "wrong size or hash on received artifact: %b", pUuid);
353 blob_reset(&content);
354 return;
355 }
356 }
357 rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
358 szU, isPriv);
359 Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]),
360 blob_size(&pXfer->aToken[1]));
361 remote_has(rid);
362 blob_reset(&content);
363 }
@@ -381,10 +426,13 @@
426 goto end_accept_unversioned_file;
427 }
428
429 /* Make sure we have a valid g.rcvid marker */
430 content_rcvid_init(0);
431
432 /* The table might not exist yet if the other side sent no uv-hash pragma */
433 unversioned_schema();
434
435 /* Check to see if current content really should be overwritten. Ideally,
436 ** a uvfile card should never have been sent unless the overwrite should
437 ** occur. But do not trust the sender. Double-check.
438 */
@@ -737,10 +785,11 @@
785 int isClient /* True if sending from client to server */
786 ){
787 Stmt q1;
788 int isFull = !isClient && (int)blob_size(pXfer->pOut)>=pXfer->mxSend;
789
790 unversioned_schema();
791 if( isFull ) noContent = 1;
792 if( noContent ){
793 db_prepare(&q1,
794 "SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
795 zName
@@ -1415,11 +1464,11 @@
1464 cgi_reset_content();
1465 @ error not\sauthorized\sto\swrite%s(whyNotAuth())
1466 nErr++;
1467 break;
1468 }
1469 xfer_accept_compressed_file(&xfer, 0, pzUuidList, pnUuidList);
1470 if( blob_size(&xfer.err) ){
1471 cgi_reset_content();
1472 @ error %T(blob_str(&xfer.err))
1473 nErr++;
1474 break;
@@ -2097,10 +2146,22 @@
2146 ** Floating-point absolute value
2147 */
2148 static double fossil_fabs(double x){
2149 return x>0.0 ? x : -x;
2150 }
2151
2152 /*
2153 ** Tell the user that unversioned content cannot be pushed because the
2154 ** server has sent the "uv-pull-only" pragma.
2155 */
2156 static void uv_pull_only_warning(void){
2157 fossil_warning(
2158 "Warning: uv-pull-only \n"
2159 " Unable to push unversioned content because you lack\n"
2160 " sufficient permission on the server\n"
2161 );
2162 }
2163
2164 /*
2165 ** Sync to the host identified in g.url.name and g.url.path. This
2166 ** routine is called by the client.
2167 **
@@ -2176,14 +2237,13 @@
2237 const char *zPX;
2238 configRcvMask = 0;
2239 configSendMask = 0;
2240 syncFlags &= ~(SYNC_PUSH);
2241 zPX = db_get("parent-project-code", 0);
2242 if( zPX==0 ){
2243 fossil_fatal("there is no parent project: set the 'parent-project-code'"
2244 " config parameter in order to pull from a parent project");
 
2245 }
2246 if( zPX ){
2247 zAltPCode = zPX;
2248 }
2249 }
@@ -2584,11 +2644,11 @@
2644 ** Client receives a compressed file transmitted from the server.
2645 */
2646 if( blob_eq(&xfer.aToken[0],"cfile")
2647 && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0
2648 ){
2649 xfer_accept_compressed_file(&xfer, (syncFlags & SYNC_CLONE)!=0, 0, 0);
2650 nArtifactRcvd++;
2651 }else
2652
2653 /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
2654 **
@@ -2731,15 +2791,11 @@
2791 "UPDATE unversioned SET mtime=%lld WHERE name=%Q", mtime, zName
2792 );
2793 db_unset("uv-hash", 0);
2794 }
2795 if( iStatus>=4 && uvPullOnly==1 ){
2796 uv_pull_only_warning();
 
 
 
 
2797 uvPullOnly = 2;
2798 }
2799 if( iStatus<=3 || uvPullOnly ){
2800 db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
2801 }else if( iStatus==4 ){
@@ -3039,10 +3095,19 @@
3095 }
3096 }
3097 nUncRcvd += blob_size(&recv);
3098 blob_reset(&recv);
3099 nCycle++;
3100
3101 /* Also warn for files that no uvigot card named */
3102 if( uvPullOnly==1 && (syncFlags & SYNC_UV_REVERT)==0
3103 && db_exists("SELECT 1 FROM uv_tosend")
3104 ){
3105 uv_pull_only_warning();
3106 uvPullOnly = 2;
3107 db_multi_exec("DELETE FROM uv_tosend");
3108 }
3109
3110 /* Set go to 1 if we need to continue the sync/push/pull/clone for
3111 ** another round. Set go to 0 if it is time to quit. */
3112 nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
3113 if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
3114
+76 -11
--- src/xfer.c
+++ src/xfer.c
@@ -256,16 +256,21 @@
256256
**
257257
** The original size of the HASH artifact is USIZE.
258258
**
259259
** If any error occurs, write a message into pErr which has already
260260
** be initialized to an empty string.
261
+**
262
+** Unless cloneFlag is set, the content must have the size USIZE and
263
+** give the HASH, or it is refused. The hash of a delta is checked only
264
+** if DELTASRC is at hand. A clone is not checked here.
261265
**
262266
** Any artifact successfully received by this routine is considered to
263267
** be public and is therefore removed from the "private" table.
264268
*/
265269
static void xfer_accept_compressed_file(
266270
Xfer *pXfer,
271
+ int cloneFlag,
267272
char **pzUuidList,
268273
int *pnUuidList
269274
){
270275
int szC; /* CSIZE */
271276
int szU; /* USIZE */
@@ -299,20 +304,60 @@
299304
}
300305
if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
301306
/* Ignore files that have been shunned */
302307
blob_reset(&content);
303308
return;
309
+ }
310
+ if( szU==0
311
+ && (blob_size(&content)<=4 || blob_uncompress(&content, &content))
312
+ ){
313
+ blob_appendf(&pXfer->err, "malformed cfile content");
314
+ blob_reset(&content);
315
+ return;
304316
}
305317
if( pXfer->nToken==5 ){
306318
srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
307319
pXfer->nDeltaRcvd++;
308320
}else{
309321
srcid = 0;
310322
pXfer->nFileRcvd++;
323
+ }
324
+ if( !cloneFlag ){
325
+ Blob *pUuid = &pXfer->aToken[1];
326
+ Blob x; /* The content, uncompressed */
327
+ Blob src, next; /* Source of a delta, and the delta applied to it */
328
+ int ok = 1;
329
+ blob_zero(&x);
330
+ if( szU==0 ){
331
+ blob_copy(&x, &content);
332
+ }else if( blob_size(&content)<=4 || blob_uncompress(&content, &x) ){
333
+ blob_appendf(&pXfer->err, "malformed cfile content");
334
+ blob_reset(&content);
335
+ return;
336
+ }
337
+ if( srcid==0 ){
338
+ ok = (int)blob_size(&x)==szU
339
+ && hname_verify_hash(&x, blob_buffer(pUuid), blob_size(pUuid));
340
+ }else if( delta_output_size(blob_buffer(&x), blob_size(&x))!=szU ){
341
+ ok = 0;
342
+ }else if( content_get(srcid, &src) ){
343
+ blob_zero(&next);
344
+ ok = blob_delta_apply(&src, &x, &next)>=0
345
+ && hname_verify_hash(&next, blob_buffer(pUuid), blob_size(pUuid));
346
+ blob_reset(&next);
347
+ blob_reset(&src);
348
+ }
349
+ blob_reset(&x);
350
+ if( !ok ){
351
+ blob_appendf(&pXfer->err,
352
+ "wrong size or hash on received artifact: %b", pUuid);
353
+ blob_reset(&content);
354
+ return;
355
+ }
311356
}
312357
rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
313
- szC, isPriv);
358
+ szU, isPriv);
314359
Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]),
315360
blob_size(&pXfer->aToken[1]));
316361
remote_has(rid);
317362
blob_reset(&content);
318363
}
@@ -381,10 +426,13 @@
381426
goto end_accept_unversioned_file;
382427
}
383428
384429
/* Make sure we have a valid g.rcvid marker */
385430
content_rcvid_init(0);
431
+
432
+ /* The table might not exist yet if the other side sent no uv-hash pragma */
433
+ unversioned_schema();
386434
387435
/* Check to see if current content really should be overwritten. Ideally,
388436
** a uvfile card should never have been sent unless the overwrite should
389437
** occur. But do not trust the sender. Double-check.
390438
*/
@@ -737,10 +785,11 @@
737785
int isClient /* True if sending from client to server */
738786
){
739787
Stmt q1;
740788
int isFull = !isClient && (int)blob_size(pXfer->pOut)>=pXfer->mxSend;
741789
790
+ unversioned_schema();
742791
if( isFull ) noContent = 1;
743792
if( noContent ){
744793
db_prepare(&q1,
745794
"SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
746795
zName
@@ -1415,11 +1464,11 @@
14151464
cgi_reset_content();
14161465
@ error not\sauthorized\sto\swrite%s(whyNotAuth())
14171466
nErr++;
14181467
break;
14191468
}
1420
- xfer_accept_compressed_file(&xfer, pzUuidList, pnUuidList);
1469
+ xfer_accept_compressed_file(&xfer, 0, pzUuidList, pnUuidList);
14211470
if( blob_size(&xfer.err) ){
14221471
cgi_reset_content();
14231472
@ error %T(blob_str(&xfer.err))
14241473
nErr++;
14251474
break;
@@ -2097,10 +2146,22 @@
20972146
** Floating-point absolute value
20982147
*/
20992148
static double fossil_fabs(double x){
21002149
return x>0.0 ? x : -x;
21012150
}
2151
+
2152
+/*
2153
+** Tell the user that unversioned content cannot be pushed because the
2154
+** server has sent the "uv-pull-only" pragma.
2155
+*/
2156
+static void uv_pull_only_warning(void){
2157
+ fossil_warning(
2158
+ "Warning: uv-pull-only \n"
2159
+ " Unable to push unversioned content because you lack\n"
2160
+ " sufficient permission on the server\n"
2161
+ );
2162
+}
21022163
21032164
/*
21042165
** Sync to the host identified in g.url.name and g.url.path. This
21052166
** routine is called by the client.
21062167
**
@@ -2176,14 +2237,13 @@
21762237
const char *zPX;
21772238
configRcvMask = 0;
21782239
configSendMask = 0;
21792240
syncFlags &= ~(SYNC_PUSH);
21802241
zPX = db_get("parent-project-code", 0);
2181
- if( zPX==0 || db_get("parent-project-name",0)==0 ){
2242
+ if( zPX==0 ){
21822243
fossil_fatal("there is no parent project: set the 'parent-project-code'"
2183
- " and 'parent-project-name' config parameters in order"
2184
- " to pull from a parent project");
2244
+ " config parameter in order to pull from a parent project");
21852245
}
21862246
if( zPX ){
21872247
zAltPCode = zPX;
21882248
}
21892249
}
@@ -2584,11 +2644,11 @@
25842644
** Client receives a compressed file transmitted from the server.
25852645
*/
25862646
if( blob_eq(&xfer.aToken[0],"cfile")
25872647
&& (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0
25882648
){
2589
- xfer_accept_compressed_file(&xfer, 0, 0);
2649
+ xfer_accept_compressed_file(&xfer, (syncFlags & SYNC_CLONE)!=0, 0, 0);
25902650
nArtifactRcvd++;
25912651
}else
25922652
25932653
/* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
25942654
**
@@ -2731,15 +2791,11 @@
27312791
"UPDATE unversioned SET mtime=%lld WHERE name=%Q", mtime, zName
27322792
);
27332793
db_unset("uv-hash", 0);
27342794
}
27352795
if( iStatus>=4 && uvPullOnly==1 ){
2736
- fossil_warning(
2737
- "Warning: uv-pull-only \n"
2738
- " Unable to push unversioned content because you lack\n"
2739
- " sufficient permission on the server\n"
2740
- );
2796
+ uv_pull_only_warning();
27412797
uvPullOnly = 2;
27422798
}
27432799
if( iStatus<=3 || uvPullOnly ){
27442800
db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
27452801
}else if( iStatus==4 ){
@@ -3039,10 +3095,19 @@
30393095
}
30403096
}
30413097
nUncRcvd += blob_size(&recv);
30423098
blob_reset(&recv);
30433099
nCycle++;
3100
+
3101
+ /* Also warn for files that no uvigot card named */
3102
+ if( uvPullOnly==1 && (syncFlags & SYNC_UV_REVERT)==0
3103
+ && db_exists("SELECT 1 FROM uv_tosend")
3104
+ ){
3105
+ uv_pull_only_warning();
3106
+ uvPullOnly = 2;
3107
+ db_multi_exec("DELETE FROM uv_tosend");
3108
+ }
30443109
30453110
/* Set go to 1 if we need to continue the sync/push/pull/clone for
30463111
** another round. Set go to 0 if it is time to quit. */
30473112
nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
30483113
if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
30493114
--- src/xfer.c
+++ src/xfer.c
@@ -256,16 +256,21 @@
256 **
257 ** The original size of the HASH artifact is USIZE.
258 **
259 ** If any error occurs, write a message into pErr which has already
260 ** be initialized to an empty string.
 
 
 
 
261 **
262 ** Any artifact successfully received by this routine is considered to
263 ** be public and is therefore removed from the "private" table.
264 */
265 static void xfer_accept_compressed_file(
266 Xfer *pXfer,
 
267 char **pzUuidList,
268 int *pnUuidList
269 ){
270 int szC; /* CSIZE */
271 int szU; /* USIZE */
@@ -299,20 +304,60 @@
299 }
300 if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
301 /* Ignore files that have been shunned */
302 blob_reset(&content);
303 return;
 
 
 
 
 
 
 
304 }
305 if( pXfer->nToken==5 ){
306 srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
307 pXfer->nDeltaRcvd++;
308 }else{
309 srcid = 0;
310 pXfer->nFileRcvd++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311 }
312 rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
313 szC, isPriv);
314 Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]),
315 blob_size(&pXfer->aToken[1]));
316 remote_has(rid);
317 blob_reset(&content);
318 }
@@ -381,10 +426,13 @@
381 goto end_accept_unversioned_file;
382 }
383
384 /* Make sure we have a valid g.rcvid marker */
385 content_rcvid_init(0);
 
 
 
386
387 /* Check to see if current content really should be overwritten. Ideally,
388 ** a uvfile card should never have been sent unless the overwrite should
389 ** occur. But do not trust the sender. Double-check.
390 */
@@ -737,10 +785,11 @@
737 int isClient /* True if sending from client to server */
738 ){
739 Stmt q1;
740 int isFull = !isClient && (int)blob_size(pXfer->pOut)>=pXfer->mxSend;
741
 
742 if( isFull ) noContent = 1;
743 if( noContent ){
744 db_prepare(&q1,
745 "SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
746 zName
@@ -1415,11 +1464,11 @@
1415 cgi_reset_content();
1416 @ error not\sauthorized\sto\swrite%s(whyNotAuth())
1417 nErr++;
1418 break;
1419 }
1420 xfer_accept_compressed_file(&xfer, pzUuidList, pnUuidList);
1421 if( blob_size(&xfer.err) ){
1422 cgi_reset_content();
1423 @ error %T(blob_str(&xfer.err))
1424 nErr++;
1425 break;
@@ -2097,10 +2146,22 @@
2097 ** Floating-point absolute value
2098 */
2099 static double fossil_fabs(double x){
2100 return x>0.0 ? x : -x;
2101 }
 
 
 
 
 
 
 
 
 
 
 
 
2102
2103 /*
2104 ** Sync to the host identified in g.url.name and g.url.path. This
2105 ** routine is called by the client.
2106 **
@@ -2176,14 +2237,13 @@
2176 const char *zPX;
2177 configRcvMask = 0;
2178 configSendMask = 0;
2179 syncFlags &= ~(SYNC_PUSH);
2180 zPX = db_get("parent-project-code", 0);
2181 if( zPX==0 || db_get("parent-project-name",0)==0 ){
2182 fossil_fatal("there is no parent project: set the 'parent-project-code'"
2183 " and 'parent-project-name' config parameters in order"
2184 " to pull from a parent project");
2185 }
2186 if( zPX ){
2187 zAltPCode = zPX;
2188 }
2189 }
@@ -2584,11 +2644,11 @@
2584 ** Client receives a compressed file transmitted from the server.
2585 */
2586 if( blob_eq(&xfer.aToken[0],"cfile")
2587 && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0
2588 ){
2589 xfer_accept_compressed_file(&xfer, 0, 0);
2590 nArtifactRcvd++;
2591 }else
2592
2593 /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
2594 **
@@ -2731,15 +2791,11 @@
2731 "UPDATE unversioned SET mtime=%lld WHERE name=%Q", mtime, zName
2732 );
2733 db_unset("uv-hash", 0);
2734 }
2735 if( iStatus>=4 && uvPullOnly==1 ){
2736 fossil_warning(
2737 "Warning: uv-pull-only \n"
2738 " Unable to push unversioned content because you lack\n"
2739 " sufficient permission on the server\n"
2740 );
2741 uvPullOnly = 2;
2742 }
2743 if( iStatus<=3 || uvPullOnly ){
2744 db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
2745 }else if( iStatus==4 ){
@@ -3039,10 +3095,19 @@
3039 }
3040 }
3041 nUncRcvd += blob_size(&recv);
3042 blob_reset(&recv);
3043 nCycle++;
 
 
 
 
 
 
 
 
 
3044
3045 /* Set go to 1 if we need to continue the sync/push/pull/clone for
3046 ** another round. Set go to 0 if it is time to quit. */
3047 nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
3048 if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
3049
--- src/xfer.c
+++ src/xfer.c
@@ -256,16 +256,21 @@
256 **
257 ** The original size of the HASH artifact is USIZE.
258 **
259 ** If any error occurs, write a message into pErr which has already
260 ** be initialized to an empty string.
261 **
262 ** Unless cloneFlag is set, the content must have the size USIZE and
263 ** give the HASH, or it is refused. The hash of a delta is checked only
264 ** if DELTASRC is at hand. A clone is not checked here.
265 **
266 ** Any artifact successfully received by this routine is considered to
267 ** be public and is therefore removed from the "private" table.
268 */
269 static void xfer_accept_compressed_file(
270 Xfer *pXfer,
271 int cloneFlag,
272 char **pzUuidList,
273 int *pnUuidList
274 ){
275 int szC; /* CSIZE */
276 int szU; /* USIZE */
@@ -299,20 +304,60 @@
304 }
305 if( uuid_is_shunned(blob_str(&pXfer->aToken[1])) ){
306 /* Ignore files that have been shunned */
307 blob_reset(&content);
308 return;
309 }
310 if( szU==0
311 && (blob_size(&content)<=4 || blob_uncompress(&content, &content))
312 ){
313 blob_appendf(&pXfer->err, "malformed cfile content");
314 blob_reset(&content);
315 return;
316 }
317 if( pXfer->nToken==5 ){
318 srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv);
319 pXfer->nDeltaRcvd++;
320 }else{
321 srcid = 0;
322 pXfer->nFileRcvd++;
323 }
324 if( !cloneFlag ){
325 Blob *pUuid = &pXfer->aToken[1];
326 Blob x; /* The content, uncompressed */
327 Blob src, next; /* Source of a delta, and the delta applied to it */
328 int ok = 1;
329 blob_zero(&x);
330 if( szU==0 ){
331 blob_copy(&x, &content);
332 }else if( blob_size(&content)<=4 || blob_uncompress(&content, &x) ){
333 blob_appendf(&pXfer->err, "malformed cfile content");
334 blob_reset(&content);
335 return;
336 }
337 if( srcid==0 ){
338 ok = (int)blob_size(&x)==szU
339 && hname_verify_hash(&x, blob_buffer(pUuid), blob_size(pUuid));
340 }else if( delta_output_size(blob_buffer(&x), blob_size(&x))!=szU ){
341 ok = 0;
342 }else if( content_get(srcid, &src) ){
343 blob_zero(&next);
344 ok = blob_delta_apply(&src, &x, &next)>=0
345 && hname_verify_hash(&next, blob_buffer(pUuid), blob_size(pUuid));
346 blob_reset(&next);
347 blob_reset(&src);
348 }
349 blob_reset(&x);
350 if( !ok ){
351 blob_appendf(&pXfer->err,
352 "wrong size or hash on received artifact: %b", pUuid);
353 blob_reset(&content);
354 return;
355 }
356 }
357 rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid,
358 szU, isPriv);
359 Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]),
360 blob_size(&pXfer->aToken[1]));
361 remote_has(rid);
362 blob_reset(&content);
363 }
@@ -381,10 +426,13 @@
426 goto end_accept_unversioned_file;
427 }
428
429 /* Make sure we have a valid g.rcvid marker */
430 content_rcvid_init(0);
431
432 /* The table might not exist yet if the other side sent no uv-hash pragma */
433 unversioned_schema();
434
435 /* Check to see if current content really should be overwritten. Ideally,
436 ** a uvfile card should never have been sent unless the overwrite should
437 ** occur. But do not trust the sender. Double-check.
438 */
@@ -737,10 +785,11 @@
785 int isClient /* True if sending from client to server */
786 ){
787 Stmt q1;
788 int isFull = !isClient && (int)blob_size(pXfer->pOut)>=pXfer->mxSend;
789
790 unversioned_schema();
791 if( isFull ) noContent = 1;
792 if( noContent ){
793 db_prepare(&q1,
794 "SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
795 zName
@@ -1415,11 +1464,11 @@
1464 cgi_reset_content();
1465 @ error not\sauthorized\sto\swrite%s(whyNotAuth())
1466 nErr++;
1467 break;
1468 }
1469 xfer_accept_compressed_file(&xfer, 0, pzUuidList, pnUuidList);
1470 if( blob_size(&xfer.err) ){
1471 cgi_reset_content();
1472 @ error %T(blob_str(&xfer.err))
1473 nErr++;
1474 break;
@@ -2097,10 +2146,22 @@
2146 ** Floating-point absolute value
2147 */
2148 static double fossil_fabs(double x){
2149 return x>0.0 ? x : -x;
2150 }
2151
2152 /*
2153 ** Tell the user that unversioned content cannot be pushed because the
2154 ** server has sent the "uv-pull-only" pragma.
2155 */
2156 static void uv_pull_only_warning(void){
2157 fossil_warning(
2158 "Warning: uv-pull-only \n"
2159 " Unable to push unversioned content because you lack\n"
2160 " sufficient permission on the server\n"
2161 );
2162 }
2163
2164 /*
2165 ** Sync to the host identified in g.url.name and g.url.path. This
2166 ** routine is called by the client.
2167 **
@@ -2176,14 +2237,13 @@
2237 const char *zPX;
2238 configRcvMask = 0;
2239 configSendMask = 0;
2240 syncFlags &= ~(SYNC_PUSH);
2241 zPX = db_get("parent-project-code", 0);
2242 if( zPX==0 ){
2243 fossil_fatal("there is no parent project: set the 'parent-project-code'"
2244 " config parameter in order to pull from a parent project");
 
2245 }
2246 if( zPX ){
2247 zAltPCode = zPX;
2248 }
2249 }
@@ -2584,11 +2644,11 @@
2644 ** Client receives a compressed file transmitted from the server.
2645 */
2646 if( blob_eq(&xfer.aToken[0],"cfile")
2647 && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0
2648 ){
2649 xfer_accept_compressed_file(&xfer, (syncFlags & SYNC_CLONE)!=0, 0, 0);
2650 nArtifactRcvd++;
2651 }else
2652
2653 /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
2654 **
@@ -2731,15 +2791,11 @@
2791 "UPDATE unversioned SET mtime=%lld WHERE name=%Q", mtime, zName
2792 );
2793 db_unset("uv-hash", 0);
2794 }
2795 if( iStatus>=4 && uvPullOnly==1 ){
2796 uv_pull_only_warning();
 
 
 
 
2797 uvPullOnly = 2;
2798 }
2799 if( iStatus<=3 || uvPullOnly ){
2800 db_multi_exec("DELETE FROM uv_tosend WHERE name=%Q", zName);
2801 }else if( iStatus==4 ){
@@ -3039,10 +3095,19 @@
3095 }
3096 }
3097 nUncRcvd += blob_size(&recv);
3098 blob_reset(&recv);
3099 nCycle++;
3100
3101 /* Also warn for files that no uvigot card named */
3102 if( uvPullOnly==1 && (syncFlags & SYNC_UV_REVERT)==0
3103 && db_exists("SELECT 1 FROM uv_tosend")
3104 ){
3105 uv_pull_only_warning();
3106 uvPullOnly = 2;
3107 db_multi_exec("DELETE FROM uv_tosend");
3108 }
3109
3110 /* Set go to 1 if we need to continue the sync/push/pull/clone for
3111 ** another round. Set go to 0 if it is time to quit. */
3112 nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
3113 if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
3114

Keyboard Shortcuts

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