Fossil SCM

If a user tries to add an attachment which is a valid control artifact, compress the attachment and append ".gz" to its names, to prevent it from being interpreted as a real control artifact. Also fix an unrelated comment typo.

drh 2012-04-17 20:37 trunk
Commit cd4e08803fc02a041067d48ade679caa9a4f88c2
3 files changed +11 -1 +1 -1 +4 -2
+11 -1
--- src/attach.c
+++ src/attach.c
@@ -238,22 +238,32 @@
238238
char *zUUID;
239239
const char *zComment;
240240
char *zDate;
241241
int rid;
242242
int i, n;
243
+ int addCompress = 0;
244
+ Manifest *pManifest;
243245
244246
db_begin_transaction();
245247
blob_init(&content, aContent, szContent);
248
+ pManifest = manifest_parse(&content, 0);
249
+ manifest_destroy(pManifest);
250
+ blob_init(&content, aContent, szContent);
251
+ if( pManifest ){
252
+ blob_compress(&content, &content);
253
+ addCompress = 1;
254
+ }
246255
rid = content_put(&content);
247256
zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
248257
blob_zero(&manifest);
249258
for(i=n=0; zName[i]; i++){
250259
if( zName[i]=='/' || zName[i]=='\\' ) n = i;
251260
}
252261
zName += n;
253262
if( zName[0]==0 ) zName = "unknown";
254
- blob_appendf(&manifest, "A %F %F %s\n", zName, zTarget, zUUID);
263
+ blob_appendf(&manifest, "A %F%s %F %s\n",
264
+ zName, addCompress ? ".gz" : "", zTarget, zUUID);
255265
zComment = PD("comment", "");
256266
while( fossil_isspace(zComment[0]) ) zComment++;
257267
n = strlen(zComment);
258268
while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
259269
if( n>0 ){
260270
--- src/attach.c
+++ src/attach.c
@@ -238,22 +238,32 @@
238 char *zUUID;
239 const char *zComment;
240 char *zDate;
241 int rid;
242 int i, n;
 
 
243
244 db_begin_transaction();
245 blob_init(&content, aContent, szContent);
 
 
 
 
 
 
 
246 rid = content_put(&content);
247 zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
248 blob_zero(&manifest);
249 for(i=n=0; zName[i]; i++){
250 if( zName[i]=='/' || zName[i]=='\\' ) n = i;
251 }
252 zName += n;
253 if( zName[0]==0 ) zName = "unknown";
254 blob_appendf(&manifest, "A %F %F %s\n", zName, zTarget, zUUID);
 
255 zComment = PD("comment", "");
256 while( fossil_isspace(zComment[0]) ) zComment++;
257 n = strlen(zComment);
258 while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
259 if( n>0 ){
260
--- src/attach.c
+++ src/attach.c
@@ -238,22 +238,32 @@
238 char *zUUID;
239 const char *zComment;
240 char *zDate;
241 int rid;
242 int i, n;
243 int addCompress = 0;
244 Manifest *pManifest;
245
246 db_begin_transaction();
247 blob_init(&content, aContent, szContent);
248 pManifest = manifest_parse(&content, 0);
249 manifest_destroy(pManifest);
250 blob_init(&content, aContent, szContent);
251 if( pManifest ){
252 blob_compress(&content, &content);
253 addCompress = 1;
254 }
255 rid = content_put(&content);
256 zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
257 blob_zero(&manifest);
258 for(i=n=0; zName[i]; i++){
259 if( zName[i]=='/' || zName[i]=='\\' ) n = i;
260 }
261 zName += n;
262 if( zName[0]==0 ) zName = "unknown";
263 blob_appendf(&manifest, "A %F%s %F %s\n",
264 zName, addCompress ? ".gz" : "", zTarget, zUUID);
265 zComment = PD("comment", "");
266 while( fossil_isspace(zComment[0]) ) zComment++;
267 n = strlen(zComment);
268 while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
269 if( n>0 ){
270
+1 -1
--- src/login.c
+++ src/login.c
@@ -385,11 +385,11 @@
385385
** is a manually operated browser or a bot. When in doubt, assume a bot.
386386
** Return true if we believe the agent is a real person.
387387
*/
388388
static int isHuman(const char *zAgent){
389389
int i;
390
- if( zAgent==0 ) return 0; /* If not UserAgent, the probably a bot */
390
+ if( zAgent==0 ) return 0; /* If not UserAgent, then probably a bot */
391391
for(i=0; zAgent[i]; i++){
392392
if( prefix_match("bot", zAgent+i) ) return 0;
393393
if( prefix_match("spider", zAgent+i) ) return 0;
394394
if( prefix_match("crawl", zAgent+i) ) return 0;
395395
/* If a URI appears in the User-Agent, it is probably a bot */
396396
--- src/login.c
+++ src/login.c
@@ -385,11 +385,11 @@
385 ** is a manually operated browser or a bot. When in doubt, assume a bot.
386 ** Return true if we believe the agent is a real person.
387 */
388 static int isHuman(const char *zAgent){
389 int i;
390 if( zAgent==0 ) return 0; /* If not UserAgent, the probably a bot */
391 for(i=0; zAgent[i]; i++){
392 if( prefix_match("bot", zAgent+i) ) return 0;
393 if( prefix_match("spider", zAgent+i) ) return 0;
394 if( prefix_match("crawl", zAgent+i) ) return 0;
395 /* If a URI appears in the User-Agent, it is probably a bot */
396
--- src/login.c
+++ src/login.c
@@ -385,11 +385,11 @@
385 ** is a manually operated browser or a bot. When in doubt, assume a bot.
386 ** Return true if we believe the agent is a real person.
387 */
388 static int isHuman(const char *zAgent){
389 int i;
390 if( zAgent==0 ) return 0; /* If not UserAgent, then probably a bot */
391 for(i=0; zAgent[i]; i++){
392 if( prefix_match("bot", zAgent+i) ) return 0;
393 if( prefix_match("spider", zAgent+i) ) return 0;
394 if( prefix_match("crawl", zAgent+i) ) return 0;
395 /* If a URI appears in the User-Agent, it is probably a bot */
396
+4 -2
--- src/manifest.c
+++ src/manifest.c
@@ -334,11 +334,11 @@
334334
** Each card is divided into tokens by a single space character.
335335
** The first token is a single upper-case letter which is the card type.
336336
** The card type determines the other parameters to the card.
337337
** Cards must occur in lexicographical order.
338338
*/
339
-static Manifest *manifest_parse(Blob *pContent, int rid){
339
+Manifest *manifest_parse(Blob *pContent, int rid){
340340
Manifest *p;
341341
int seenZ = 0;
342342
int i, lineNo=0;
343343
ManifestText x;
344344
char cPrevType = 0;
@@ -348,11 +348,13 @@
348348
char *zUuid;
349349
int sz = 0;
350350
int isRepeat;
351351
static Bag seen;
352352
353
- if( bag_find(&seen, rid) ){
353
+ if( rid==0 ){
354
+ isRepeat = 1;
355
+ }else if( bag_find(&seen, rid) ){
354356
isRepeat = 1;
355357
}else{
356358
isRepeat = 0;
357359
bag_insert(&seen, rid);
358360
}
359361
--- src/manifest.c
+++ src/manifest.c
@@ -334,11 +334,11 @@
334 ** Each card is divided into tokens by a single space character.
335 ** The first token is a single upper-case letter which is the card type.
336 ** The card type determines the other parameters to the card.
337 ** Cards must occur in lexicographical order.
338 */
339 static Manifest *manifest_parse(Blob *pContent, int rid){
340 Manifest *p;
341 int seenZ = 0;
342 int i, lineNo=0;
343 ManifestText x;
344 char cPrevType = 0;
@@ -348,11 +348,13 @@
348 char *zUuid;
349 int sz = 0;
350 int isRepeat;
351 static Bag seen;
352
353 if( bag_find(&seen, rid) ){
 
 
354 isRepeat = 1;
355 }else{
356 isRepeat = 0;
357 bag_insert(&seen, rid);
358 }
359
--- src/manifest.c
+++ src/manifest.c
@@ -334,11 +334,11 @@
334 ** Each card is divided into tokens by a single space character.
335 ** The first token is a single upper-case letter which is the card type.
336 ** The card type determines the other parameters to the card.
337 ** Cards must occur in lexicographical order.
338 */
339 Manifest *manifest_parse(Blob *pContent, int rid){
340 Manifest *p;
341 int seenZ = 0;
342 int i, lineNo=0;
343 ManifestText x;
344 char cPrevType = 0;
@@ -348,11 +348,13 @@
348 char *zUuid;
349 int sz = 0;
350 int isRepeat;
351 static Bag seen;
352
353 if( rid==0 ){
354 isRepeat = 1;
355 }else if( bag_find(&seen, rid) ){
356 isRepeat = 1;
357 }else{
358 isRepeat = 0;
359 bag_insert(&seen, rid);
360 }
361

Keyboard Shortcuts

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