Fossil SCM
In xfer_accept_compressed_file(), refuse a cfile card whose content does not have the size and the hash that the card gives, as xfer_accept_file() does for a file card. The content was stored unchecked, and the mismatch was found only by the check before commit, which ends the process with abort(). A delta is checked against its hash only if its source is at hand, and a clone is not checked, as before.
Commit
ab28f6ca06d951acdae1deffbe3b5e3e64d7dc242b7e9eca80c6167254657e99
Parent
d80d75c67978037…
1 file changed
+41
-2
+41
-2
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -250,16 +250,22 @@ | ||
| 250 | 250 | ** |
| 251 | 251 | ** The original size of the HASH artifact is USIZE. |
| 252 | 252 | ** |
| 253 | 253 | ** If any error occurs, write a message into pErr which has already |
| 254 | 254 | ** be initialized to an empty string. |
| 255 | +** | |
| 256 | +** Unless cloneFlag is set, the content must have the size USIZE and | |
| 257 | +** give the HASH, or it is refused. The hash of a delta is checked only | |
| 258 | +** if DELTASRC is at hand. A clone is not checked here, as it is not in | |
| 259 | +** xfer_accept_file(). | |
| 255 | 260 | ** |
| 256 | 261 | ** Any artifact successfully received by this routine is considered to |
| 257 | 262 | ** be public and is therefore removed from the "private" table. |
| 258 | 263 | */ |
| 259 | 264 | static void xfer_accept_compressed_file( |
| 260 | 265 | Xfer *pXfer, |
| 266 | + int cloneFlag, | |
| 261 | 267 | char **pzUuidList, |
| 262 | 268 | int *pnUuidList |
| 263 | 269 | ){ |
| 264 | 270 | int szC; /* CSIZE */ |
| 265 | 271 | int szU; /* USIZE */ |
| @@ -309,10 +315,43 @@ | ||
| 309 | 315 | srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv); |
| 310 | 316 | pXfer->nDeltaRcvd++; |
| 311 | 317 | }else{ |
| 312 | 318 | srcid = 0; |
| 313 | 319 | pXfer->nFileRcvd++; |
| 320 | + } | |
| 321 | + if( !cloneFlag ){ | |
| 322 | + Blob *pUuid = &pXfer->aToken[1]; | |
| 323 | + Blob x; /* The content, uncompressed */ | |
| 324 | + Blob src, next; /* Source of a delta, and the delta applied to it */ | |
| 325 | + int ok = 1; | |
| 326 | + blob_zero(&x); | |
| 327 | + if( szU==0 ){ | |
| 328 | + blob_copy(&x, &content); | |
| 329 | + }else if( blob_size(&content)<=4 || blob_uncompress(&content, &x) ){ | |
| 330 | + blob_appendf(&pXfer->err, "malformed cfile content"); | |
| 331 | + blob_reset(&content); | |
| 332 | + return; | |
| 333 | + } | |
| 334 | + if( srcid==0 ){ | |
| 335 | + ok = (int)blob_size(&x)==szU | |
| 336 | + && hname_verify_hash(&x, blob_buffer(pUuid), blob_size(pUuid)); | |
| 337 | + }else if( delta_output_size(blob_buffer(&x), blob_size(&x))!=szU ){ | |
| 338 | + ok = 0; | |
| 339 | + }else if( content_get(srcid, &src) ){ | |
| 340 | + blob_zero(&next); | |
| 341 | + ok = blob_delta_apply(&src, &x, &next)>=0 | |
| 342 | + && hname_verify_hash(&next, blob_buffer(pUuid), blob_size(pUuid)); | |
| 343 | + blob_reset(&next); | |
| 344 | + blob_reset(&src); | |
| 345 | + } | |
| 346 | + blob_reset(&x); | |
| 347 | + if( !ok ){ | |
| 348 | + blob_appendf(&pXfer->err, | |
| 349 | + "wrong size or hash on received artifact: %b", pUuid); | |
| 350 | + blob_reset(&content); | |
| 351 | + return; | |
| 352 | + } | |
| 314 | 353 | } |
| 315 | 354 | rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, |
| 316 | 355 | szU, isPriv); |
| 317 | 356 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), |
| 318 | 357 | blob_size(&pXfer->aToken[1])); |
| @@ -1418,11 +1457,11 @@ | ||
| 1418 | 1457 | cgi_reset_content(); |
| 1419 | 1458 | @ error not\sauthorized\sto\swrite%s(whyNotAuth()) |
| 1420 | 1459 | nErr++; |
| 1421 | 1460 | break; |
| 1422 | 1461 | } |
| 1423 | - xfer_accept_compressed_file(&xfer, pzUuidList, pnUuidList); | |
| 1462 | + xfer_accept_compressed_file(&xfer, 0, pzUuidList, pnUuidList); | |
| 1424 | 1463 | if( blob_size(&xfer.err) ){ |
| 1425 | 1464 | cgi_reset_content(); |
| 1426 | 1465 | @ error %T(blob_str(&xfer.err)) |
| 1427 | 1466 | nErr++; |
| 1428 | 1467 | break; |
| @@ -2587,11 +2626,11 @@ | ||
| 2587 | 2626 | ** Client receives a compressed file transmitted from the server. |
| 2588 | 2627 | */ |
| 2589 | 2628 | if( blob_eq(&xfer.aToken[0],"cfile") |
| 2590 | 2629 | && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0 |
| 2591 | 2630 | ){ |
| 2592 | - xfer_accept_compressed_file(&xfer, 0, 0); | |
| 2631 | + xfer_accept_compressed_file(&xfer, (syncFlags & SYNC_CLONE)!=0, 0, 0); | |
| 2593 | 2632 | nArtifactRcvd++; |
| 2594 | 2633 | }else |
| 2595 | 2634 | |
| 2596 | 2635 | /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT |
| 2597 | 2636 | ** |
| 2598 | 2637 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -250,16 +250,22 @@ | |
| 250 | ** |
| 251 | ** The original size of the HASH artifact is USIZE. |
| 252 | ** |
| 253 | ** If any error occurs, write a message into pErr which has already |
| 254 | ** be initialized to an empty string. |
| 255 | ** |
| 256 | ** Any artifact successfully received by this routine is considered to |
| 257 | ** be public and is therefore removed from the "private" table. |
| 258 | */ |
| 259 | static void xfer_accept_compressed_file( |
| 260 | Xfer *pXfer, |
| 261 | char **pzUuidList, |
| 262 | int *pnUuidList |
| 263 | ){ |
| 264 | int szC; /* CSIZE */ |
| 265 | int szU; /* USIZE */ |
| @@ -309,10 +315,43 @@ | |
| 309 | srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv); |
| 310 | pXfer->nDeltaRcvd++; |
| 311 | }else{ |
| 312 | srcid = 0; |
| 313 | pXfer->nFileRcvd++; |
| 314 | } |
| 315 | rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, |
| 316 | szU, isPriv); |
| 317 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), |
| 318 | blob_size(&pXfer->aToken[1])); |
| @@ -1418,11 +1457,11 @@ | |
| 1418 | cgi_reset_content(); |
| 1419 | @ error not\sauthorized\sto\swrite%s(whyNotAuth()) |
| 1420 | nErr++; |
| 1421 | break; |
| 1422 | } |
| 1423 | xfer_accept_compressed_file(&xfer, pzUuidList, pnUuidList); |
| 1424 | if( blob_size(&xfer.err) ){ |
| 1425 | cgi_reset_content(); |
| 1426 | @ error %T(blob_str(&xfer.err)) |
| 1427 | nErr++; |
| 1428 | break; |
| @@ -2587,11 +2626,11 @@ | |
| 2587 | ** Client receives a compressed file transmitted from the server. |
| 2588 | */ |
| 2589 | if( blob_eq(&xfer.aToken[0],"cfile") |
| 2590 | && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0 |
| 2591 | ){ |
| 2592 | xfer_accept_compressed_file(&xfer, 0, 0); |
| 2593 | nArtifactRcvd++; |
| 2594 | }else |
| 2595 | |
| 2596 | /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT |
| 2597 | ** |
| 2598 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -250,16 +250,22 @@ | |
| 250 | ** |
| 251 | ** The original size of the HASH artifact is USIZE. |
| 252 | ** |
| 253 | ** If any error occurs, write a message into pErr which has already |
| 254 | ** be initialized to an empty string. |
| 255 | ** |
| 256 | ** Unless cloneFlag is set, the content must have the size USIZE and |
| 257 | ** give the HASH, or it is refused. The hash of a delta is checked only |
| 258 | ** if DELTASRC is at hand. A clone is not checked here, as it is not in |
| 259 | ** xfer_accept_file(). |
| 260 | ** |
| 261 | ** Any artifact successfully received by this routine is considered to |
| 262 | ** be public and is therefore removed from the "private" table. |
| 263 | */ |
| 264 | static void xfer_accept_compressed_file( |
| 265 | Xfer *pXfer, |
| 266 | int cloneFlag, |
| 267 | char **pzUuidList, |
| 268 | int *pnUuidList |
| 269 | ){ |
| 270 | int szC; /* CSIZE */ |
| 271 | int szU; /* USIZE */ |
| @@ -309,10 +315,43 @@ | |
| 315 | srcid = rid_from_uuid(&pXfer->aToken[2], 1, isPriv); |
| 316 | pXfer->nDeltaRcvd++; |
| 317 | }else{ |
| 318 | srcid = 0; |
| 319 | pXfer->nFileRcvd++; |
| 320 | } |
| 321 | if( !cloneFlag ){ |
| 322 | Blob *pUuid = &pXfer->aToken[1]; |
| 323 | Blob x; /* The content, uncompressed */ |
| 324 | Blob src, next; /* Source of a delta, and the delta applied to it */ |
| 325 | int ok = 1; |
| 326 | blob_zero(&x); |
| 327 | if( szU==0 ){ |
| 328 | blob_copy(&x, &content); |
| 329 | }else if( blob_size(&content)<=4 || blob_uncompress(&content, &x) ){ |
| 330 | blob_appendf(&pXfer->err, "malformed cfile content"); |
| 331 | blob_reset(&content); |
| 332 | return; |
| 333 | } |
| 334 | if( srcid==0 ){ |
| 335 | ok = (int)blob_size(&x)==szU |
| 336 | && hname_verify_hash(&x, blob_buffer(pUuid), blob_size(pUuid)); |
| 337 | }else if( delta_output_size(blob_buffer(&x), blob_size(&x))!=szU ){ |
| 338 | ok = 0; |
| 339 | }else if( content_get(srcid, &src) ){ |
| 340 | blob_zero(&next); |
| 341 | ok = blob_delta_apply(&src, &x, &next)>=0 |
| 342 | && hname_verify_hash(&next, blob_buffer(pUuid), blob_size(pUuid)); |
| 343 | blob_reset(&next); |
| 344 | blob_reset(&src); |
| 345 | } |
| 346 | blob_reset(&x); |
| 347 | if( !ok ){ |
| 348 | blob_appendf(&pXfer->err, |
| 349 | "wrong size or hash on received artifact: %b", pUuid); |
| 350 | blob_reset(&content); |
| 351 | return; |
| 352 | } |
| 353 | } |
| 354 | rid = content_put_ex(&content, blob_str(&pXfer->aToken[1]), srcid, |
| 355 | szU, isPriv); |
| 356 | Th_AppendToList(pzUuidList, pnUuidList, blob_str(&pXfer->aToken[1]), |
| 357 | blob_size(&pXfer->aToken[1])); |
| @@ -1418,11 +1457,11 @@ | |
| 1457 | cgi_reset_content(); |
| 1458 | @ error not\sauthorized\sto\swrite%s(whyNotAuth()) |
| 1459 | nErr++; |
| 1460 | break; |
| 1461 | } |
| 1462 | xfer_accept_compressed_file(&xfer, 0, pzUuidList, pnUuidList); |
| 1463 | if( blob_size(&xfer.err) ){ |
| 1464 | cgi_reset_content(); |
| 1465 | @ error %T(blob_str(&xfer.err)) |
| 1466 | nErr++; |
| 1467 | break; |
| @@ -2587,11 +2626,11 @@ | |
| 2626 | ** Client receives a compressed file transmitted from the server. |
| 2627 | */ |
| 2628 | if( blob_eq(&xfer.aToken[0],"cfile") |
| 2629 | && (syncFlags & (SYNC_PULL|SYNC_CLONE))!=0 |
| 2630 | ){ |
| 2631 | xfer_accept_compressed_file(&xfer, (syncFlags & SYNC_CLONE)!=0, 0, 0); |
| 2632 | nArtifactRcvd++; |
| 2633 | }else |
| 2634 | |
| 2635 | /* uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT |
| 2636 | ** |
| 2637 |