@@ -351,6 +351,10 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
351
351
strcat (path , suff );
352
352
//memcpy(path + off, suff, GIT_PATH_MAX - off - STRLEN(suff) - 1);
353
353
354
+ if (memcmp (buf -> data , "PACK" , STRLEN ("PACK" ))) {
355
+ return git__throw (GIT_ERROR , "The pack doesn't start with the signature" );
356
+ }
357
+
354
358
error = git_filebuf_open (& file , path , GIT_FILEBUF_TEMPORARY );
355
359
if (error < GIT_SUCCESS )
356
360
goto cleanup ;
@@ -387,15 +391,15 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
387
391
static int git_download_pack (char * * out , git_transport * transport , git_repository * repo )
388
392
{
389
393
transport_git * t = (transport_git * ) transport ;
390
- int s = t -> socket , error = GIT_SUCCESS , pack = 0 ;
394
+ int s = t -> socket , error = GIT_SUCCESS ;
391
395
gitno_buffer buf ;
392
396
char buffer [1024 ];
393
397
git_pkt * pkt ;
394
398
const char * line_end , * ptr ;
395
399
396
400
gitno_buffer_setup (& buf , buffer , sizeof (buffer ), s );
397
401
/*
398
- * First , we ignore any ACKs and wait for a NACK
402
+ * For now , we ignore everything and wait for the pack
399
403
*/
400
404
while (1 ) {
401
405
error = gitno_recv (& buf );
@@ -406,7 +410,7 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor
406
410
407
411
ptr = buf .data ;
408
412
/* Whilst we're searching for the pack */
409
- while (! pack ) {
413
+ while (1 ) {
410
414
if (buf .offset == 0 )
411
415
break ;
412
416
error = git_pkt_parse_line (& pkt , ptr , & line_end , buf .offset );
@@ -415,21 +419,14 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor
415
419
if (error < GIT_SUCCESS )
416
420
return error ;
417
421
418
- gitno_consume ( & buf , line_end );
419
- if ( pkt -> type == GIT_PKT_PACK )
420
- pack = 1 ;
422
+ if ( pkt -> type == GIT_PKT_PACK ) {
423
+ return store_pack ( out , & buf , repo );
424
+ }
421
425
/* For now we don't care about anything */
422
426
free (pkt );
427
+ gitno_consume (& buf , line_end );
423
428
}
424
-
425
- /*
426
- * No we have the packet, let's just put anything we get now
427
- * into a packfile
428
- */
429
- return store_pack (out , & buf , repo );
430
429
}
431
-
432
- return error ;
433
430
}
434
431
435
432
0 commit comments