Fossil SCM

Use generic hash validity checking in the purge.c module.

drh 2017-03-01 00:49 fossil-2.0
Commit 7bd36bc52dca8d524fd235302e3e701f6d939292
1 file changed +6 -12
+6 -12
--- src/purge.c
+++ src/purge.c
@@ -347,11 +347,11 @@
347347
int piid, /* ID of the item to extract */
348348
Blob *pOut /* Write the content into this blob */
349349
){
350350
Stmt q;
351351
int srcid;
352
- Blob h1, h2, x;
352
+ Blob h1, x;
353353
static Bag busy;
354354
355355
db_prepare(&q, "SELECT uuid, srcid, data FROM purgeitem"
356356
" WHERE piid=%d", piid);
357357
if( db_step(&q)!=SQLITE_ROW ){
@@ -376,17 +376,14 @@
376376
blob_reset(&baseline);
377377
}
378378
bag_remove(&busy, piid);
379379
blob_zero(&h1);
380380
db_column_blob(&q, 0, &h1);
381
- sha1sum_blob(pOut, &h2);
382
- if( blob_compare(&h1, &h2)!=0 ){
383
- fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
384
- blob_str(&h1), blob_str(&h2));
381
+ if( hname_verify_hash(pOut, blob_buffer(&h1), blob_size(&h1))==0 ){
382
+ fossil_fatal("incorrect artifact hash on %b", &h1);
385383
}
386384
blob_reset(&h1);
387
- blob_reset(&h2);
388385
db_finalize(&q);
389386
return 0;
390387
}
391388
392389
/*
@@ -411,11 +408,11 @@
411408
" WHERE ix.srcid=%d"
412409
" AND ix.piid=purgeitem.piid;",
413410
iSrc
414411
);
415412
while( db_step(&q)==SQLITE_ROW ){
416
- Blob h1, h2, c1, c2;
413
+ Blob h1, c1, c2;
417414
int isPriv, rid;
418415
blob_zero(&h1);
419416
db_column_blob(&q, 0, &h1);
420417
blob_zero(&c1);
421418
db_column_blob(&q, 1, &c1);
@@ -425,16 +422,13 @@
425422
blob_delta_apply(pBasis, &c1, &c2);
426423
blob_reset(&c1);
427424
}else{
428425
c2 = c1;
429426
}
430
- sha1sum_blob(&c2, &h2);
431
- if( blob_compare(&h1, &h2)!=0 ){
432
- fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
433
- blob_str(&h1), blob_str(&h2));
427
+ if( hname_verify_hash(&c2, blob_buffer(&h1), blob_size(&h1))==0 ){
428
+ fossil_fatal("incorrect hash on %b", &h1);
434429
}
435
- blob_reset(&h2);
436430
isPriv = db_column_int(&q, 2);
437431
rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
438432
if( rid==0 ){
439433
fossil_fatal("%s", g.zErrMsg);
440434
}else{
441435
--- src/purge.c
+++ src/purge.c
@@ -347,11 +347,11 @@
347 int piid, /* ID of the item to extract */
348 Blob *pOut /* Write the content into this blob */
349 ){
350 Stmt q;
351 int srcid;
352 Blob h1, h2, x;
353 static Bag busy;
354
355 db_prepare(&q, "SELECT uuid, srcid, data FROM purgeitem"
356 " WHERE piid=%d", piid);
357 if( db_step(&q)!=SQLITE_ROW ){
@@ -376,17 +376,14 @@
376 blob_reset(&baseline);
377 }
378 bag_remove(&busy, piid);
379 blob_zero(&h1);
380 db_column_blob(&q, 0, &h1);
381 sha1sum_blob(pOut, &h2);
382 if( blob_compare(&h1, &h2)!=0 ){
383 fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
384 blob_str(&h1), blob_str(&h2));
385 }
386 blob_reset(&h1);
387 blob_reset(&h2);
388 db_finalize(&q);
389 return 0;
390 }
391
392 /*
@@ -411,11 +408,11 @@
411 " WHERE ix.srcid=%d"
412 " AND ix.piid=purgeitem.piid;",
413 iSrc
414 );
415 while( db_step(&q)==SQLITE_ROW ){
416 Blob h1, h2, c1, c2;
417 int isPriv, rid;
418 blob_zero(&h1);
419 db_column_blob(&q, 0, &h1);
420 blob_zero(&c1);
421 db_column_blob(&q, 1, &c1);
@@ -425,16 +422,13 @@
425 blob_delta_apply(pBasis, &c1, &c2);
426 blob_reset(&c1);
427 }else{
428 c2 = c1;
429 }
430 sha1sum_blob(&c2, &h2);
431 if( blob_compare(&h1, &h2)!=0 ){
432 fossil_fatal("SHA1 hash mismatch - wanted %s, got %s",
433 blob_str(&h1), blob_str(&h2));
434 }
435 blob_reset(&h2);
436 isPriv = db_column_int(&q, 2);
437 rid = content_put_ex(&c2, blob_str(&h1), 0, 0, isPriv);
438 if( rid==0 ){
439 fossil_fatal("%s", g.zErrMsg);
440 }else{
441
--- src/purge.c
+++ src/purge.c
@@ -347,11 +347,11 @@
347 int piid, /* ID of the item to extract */
348 Blob *pOut /* Write the content into this blob */
349 ){
350 Stmt q;
351 int srcid;
352 Blob h1, x;
353 static Bag busy;
354
355 db_prepare(&q, "SELECT uuid, srcid, data FROM purgeitem"
356 " WHERE piid=%d", piid);
357 if( db_step(&q)!=SQLITE_ROW ){
@@ -376,17 +376,14 @@
376 blob_reset(&baseline);
377 }
378 bag_remove(&busy, piid);
379 blob_zero(&h1);
380 db_column_blob(&q, 0, &h1);
381 if( hname_verify_hash(pOut, blob_buffer(&h1), blob_size(&h1))==0 ){
382 fossil_fatal("incorrect artifact hash on %b", &h1);
 
 
383 }
384 blob_reset(&h1);
 
385 db_finalize(&q);
386 return 0;
387 }
388
389 /*
@@ -411,11 +408,11 @@
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);
@@ -425,16 +422,13 @@
422 blob_delta_apply(pBasis, &c1, &c2);
423 blob_reset(&c1);
424 }else{
425 c2 = c1;
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

Keyboard Shortcuts

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